我正在使用Tomcat 6(但是对于Tomcat 7也应该适用)。假设我的web.xml
包含以下定义:
<error-page>
<error-code>401</error-code>
<location>/Handle401Error.jsp</location>
</error-page>
假设我现在从某个其他的Servlet/JSP返回HTTP 401:
httpResponse.sendError(SC_UNAUTHORIZED, "This is a message");
我如何在
Handle401Error.jsp
中访问HTTP响应文本(“This is a message”)?Tomcat的做法是,在显示类似于此错误页面时,使用Valve
(ErrorReportValve
)。我也需要编写一个Valve
吗?编辑:下面的被接受答案正是我一直在寻找的,而假定的重复问题并没有提到相同的解决方案。