几种 处理 程序中的异常+ 框架中拦截器的使用(自定义拦截器);
局部异常:针对某个action
异常处理标签:<exception-mapping result=”名称” exception=”异常类型”></<exception-mapping>
<result name=”名称”>异常同一处理的界面</result>
<action name="division_*" class="com.zgq.action.ExceptionAction" method="{1}">
<exception-mapping result="error1" exception="java.lang.ArithmeticException"></exception-mapping>
<result name="error1">/errorOne.jsp</result>
</action>
全局异常:程序中的所有,继承了该包 的action类
<global-result>
<result name = “error”>/error.jsp</resutl>
</global-result>
<package name="pk" extends="json-default,struts-default" namespace="/">
<global-results>
<result name="error2">/errorTwo.jsp</result>
</global-results>
<global-exception-mappings>
<exception-mapping result="error2" exception="java.lang.ArrayIndexOutOfBoundsException"></exception-mapping>
</global-exception-mappings>
<action name="login" class="com.zgq.action.LoginAction">
<result name="success">/success.jsp</result>
<result name="yes">/showInfo.jsp</result>
</action>
<action name="division_*" class="com.zgq.action.ExceptionAction" method="{1}">
<exception-mapping result="error1" exception="java.lang.ArithmeticException"></exception-mapping>
<result name="error1">/errorOne.jsp</result>
</action>
</package>
范围更广的异常类型处理
在 web.xml中配置,状态码异常,它的优先级 高于其他任何异常;
<error-page>
<error-code>404</error-code>
<location>/errorThree.jsp</location>
</error-page>