why error-page in web.xml cannot capture exceptions thrown from struts2 prepare method
i declare a global exception handler in web.xml
<error-page>
<exception-type>java.lang.Throwa开发者_如何学运维ble</exception-type>
<location>/exceptionHandler</location>
</error-page>
it works fine most of the time. But it cannot capture the exceptions thrown from the prepare method in struts2 actions
anyone know why
Probably because Struts2's ExceptionMappingInterceptor
catches exceptions and maps them to error pages itself.
You can use the following in your struts.xml:
<global-results>
<result name="error">/WEB-INF/error.jsp</result>
</global-results>
<global-exception-mappings>
<exception-mapping exception="java.lang.Exception" result="error"/>
</global-exception-mappings>
Alternatively, you could remove the ExceptionMappingInterceptor
from the interceptor stack if you really want to use the web.xml method.
精彩评论