开发者

Grails: Mapping to response codes, impossible to change http status code

"404" (controller: 'error', action: 'pageNotFound')

Any changes to response.status inside the pageNotFound action is reverted back to 404 before the response is sent to the client. Is it possible to work around this开发者_JAVA技巧 some way? I would like to be able to change it to 410 when I detect that the resource has been deleted or 301 when it's moved permanently.


If that's not working try this in your error controller:

class ErrorController {

    def notFound = {
        redirect( action: 'gone')
      }

    def gone= {
        response.sendError(410, "Gone")
    }
}


Try setting the header yourself manually by response.setHeader()

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜