开发者

Grails URLMappings for 404 doesn't work properly

I have a strange problem with handling 404 HTTP response in grails 1.3.6 (the same wrong behavior was in 1.3.5). It sometimes works but most of the time it doesn't. I think it is a grails bug but haven't found any bug in grails' jira.. whenever I request for bad URL I receive default Tomcat 404 page. My Configuration/UrlMappings.groovy looks like:

class UrlMappings {

    static mappings = {
        "404" {开发者_StackOverflow中文版
            controller = 'customError'
            action = 'index'
            code = 404
        }
        "500" {
            controller = 'customError'
            action = 'index'
            code = 500
        }

        "/"(controller: "home", action: "index")
        "/$controller/$action?/$id?"{
            constraints {
            // id has to be a number
                id(matches: /\d+/)
            }
        }
    }
}

Doesn anybody know how to solve it?:-)

Best, Mateo


I think the problem is you are using braces { } instead of using parenthesis ( ). This is how it should be listed for your example of using a customError controller.

static mappings = {

"404"(controller: "customError", action: "index")

"500"(controller: "customError", action: "index")

...

}

Please see [6.4.4 in the Grails documentation][1] for more information.

[1]: http://grails.org/doc/latest/guide/6.%20The%20Web%20Layer.html#6.4.4 Mapping to Response Codes


Try it without the space. There was a bug in older versions of Grails where a space would cause the error mappings not to be picked up due to a bug in some regex somewhere:

static mappings = {
    "404"{
          controller = 'customError'
           action = 'index'
        code = 404
    }
    "500"{
        controller = 'customError'
        action = 'index'
        code = 500
    }
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜