mjn*_*mjn 6 java error-handling jsf web.xml servlets
在我的web.xml中,500错误由JSF页面处理:
<error-page>
<error-code>500</error-code>
<location>/errorpage.html</location>
</error-page>
Run Code Online (Sandbox Code Playgroud)
如果容器处理500错误并调用此JSF页面,请求中是否包含请求参数或正文内容,其中包含完整的错误消息?
例如,如果我在Servlet中使用此代码来提供错误描述并出现500错误:
response.sendError(HttpURLConnection.HTTP_INTERNAL_ERROR, "Some error message");
Run Code Online (Sandbox Code Playgroud)
有没有一种标准的方法来从请求中获取文本"一些错误消息"?
Bal*_*usC 10
它可以作为请求属性使用,其键RequestDispatcher#ERROR_MESSAGE
是"javax.servlet.error.message"
.所以,这应该做:
<p>The error message is: #{requestScope['javax.servlet.error.message']}</p>
Run Code Online (Sandbox Code Playgroud)
(注意:我假设您正在使用Facelets;对于JSP,您必须将其放入<h:outputText>
)
归档时间: |
|
查看次数: |
5944 次 |
最近记录: |