0

My mappings look like

static mappings = {
    "/"      (controller : "welcome",    action : "index")
    "/about" (controller : "welcome",    action : "about")
    "404"    (controller : "welcome",    action : "notFound")
}

This doesn't seem to catch 404 requests as I still get the default Tomcat 404 page. I have also tried the closure based method (below) with no success.

    "404" {
        controller = "welcome"
        action = "notFound"
    }

Versions:

versions: {
app.version: "0.1"
app.servlet.version: "2.4"
app.grails.version: "1.3.5"
plugins.tomcat: "1.3.5"
plugins.hibernate: "1.3.5"
}
skaffman
  • 398,947
  • 96
  • 818
  • 769
Josh K
  • 28,364
  • 20
  • 86
  • 132

2 Answers2

2

I have succeeded by removing whitespace on the 404 line:

"404"(controller : "welcome",    action : "notFound")
Josh K
  • 28,364
  • 20
  • 86
  • 132
0

What version of Grails are you running?

Also, what does your controller action look like? This person seems to have resolved the issue by using a redirect in their controller instead of a render:

Problems with Grails 404 UrlMapping

def notFound = {
  redirect(uri:"/404.html")
}
Community
  • 1
  • 1
Ethan Shepherd
  • 569
  • 3
  • 13
  • Version is in the original question: `app.grails.version: "1.3.5"`. I don't want to redirect to a static page, would like to render a specific error message in JSON (this is an API). – Josh K Mar 02 '11 at 20:28
  • You could make a redirect to an uri, and have that uri render your controller and action. Perhaps this will solve your problem? – sbglasius Mar 03 '11 at 08:52
  • @sbglasius: No, because I don't want to issue a redirect. I want to display content with a 404 header. – Josh K Mar 03 '11 at 15:42