Tomcat Grails自定义错误页(500)&;雄猫
我试图在Grails代码抛出任何未处理的异常之后实现简单的自定义错误页。我已将500映射到我的控制器:Tomcat Grails自定义错误页(500)&;雄猫,tomcat,grails,exception-handling,Tomcat,Grails,Exception Handling,我试图在Grails代码抛出任何未处理的异常之后实现简单的自定义错误页。我已将500映射到我的控制器: "500" ( controller: "error", action: "serverError" ) def serverError = { try { // first check, if some exception was reported if (!request.exception)
"500" (
controller: "error",
action: "serverError"
)
def serverError = {
try {
// first check, if some exception was reported
if (!request.exception) {
return
}
// send mail with stack trace if requested
if (shouldSendErrorReports) {
log.debug "Mail was sent out successfully..."
}
} catch (Throwable e) {
log.error "Error while reporting an error: " + e
}
// redirect to error message
redirect (
action: "errorMessage"
)
}
// lines omitted for clarity
}
}
并在控制器中处理异常:
"500" (
controller: "error",
action: "serverError"
)
def serverError = {
try {
// first check, if some exception was reported
if (!request.exception) {
return
}
// send mail with stack trace if requested
if (shouldSendErrorReports) {
log.debug "Mail was sent out successfully..."
}
} catch (Throwable e) {
log.error "Error while reporting an error: " + e
}
// redirect to error message
redirect (
action: "errorMessage"
)
}
// lines omitted for clarity
}
}
“errorMessage”操作只是一个简单的视图,默认情况下呈现GSP页面,其中包含静态内容——信息并单击以重定向窗口。
该页面(我希望)有正确的序言:
<%@ page contentType="text/html;charset=UTF-8" %>
<%@ page isErrorPage="true" %>
}
}
现在,当通过NetBeans(Jetty)在本地测试它时,一切正常,并显示errorMessage页面;部署到测试环境(Tomcat6)时,将显示Tomcat堆栈跟踪
}
}
如何防止显示此Tomcat堆栈跟踪?我有两个想法——首先,我没有正确地转储(处理?)异常,所以它会冒泡到Tomcat——其次,Tomcat设置了一些配置值,所以它无论如何都会显示堆栈跟踪
}
}
如果你对此有任何想法,请告诉我。花5个小时来解决这个问题…:-/
}
}
谢谢大家! def错误={
}
}
def exception=request['javax.servlet.error.exception']?.cause?.cause
如果(例外){
}
}
自从你问这个问题已经一年多了,但只是为了让其他人也能受益
}
}
你试过错误页面修复插件吗?
抱歉,不是这样……我可以使用request.exception获取异常本身,但无法阻止它向tomcat的处理程序传播。。。
}
}