开发者

why error-page in web.xml cannot capture exceptions thrown from struts2 prepare method

开发者 https://www.devze.com 2023-03-28 20:36 出处:网络
i declare a global exception handler in web.xml <error-page> <exception-type>java.lang.Throwa开发者_如何学运维ble</exception-type>

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.

0

精彩评论

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

关注公众号