开发者

Unable to create a 404 page in Grails

开发者 https://www.devze.com 2023-02-14 22:18 出处:网络
My mappings look like static mappings = { \"/\"(controller : \"welcome\",action : \"index\") \"/about\" (controller : \"welcome\",action : \"about\")

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开发者_StackOverflow中文版: "1.3.5"
plugins.hibernate: "1.3.5"
}


I have succeeded by removing whitespace on the 404 line:

"404"(controller : "welcome",    action : "notFound")


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")
}
0

精彩评论

暂无评论...
验证码 换一张
取 消