Struts异常处理
struts2中通过拦截器对action抛出的异常进行捕获,这个拦截器是 ExceptionMappingInterceptor
此拦截在Struts2的struts-default.xml中进行了配置,只需要使用exception-maping元素来配置异常映射
exception-mapping有二个属性:
exception
指定一个异常类型的完整类名
result
指定对该异常进行处理的结果的名字。
</pre><pre name="code" class="html">
<package name=“pass” extends=“struts-default” namespace=“/”>
<gboal-results>
<result name=“sqlException” type=“redirectAction”>/login.action</result>
<result name=“error” >/error.jsp</result>
</gboal-results>
<gboal-exception-mappings>
<exception-mapping exception=“java.sql.SQLException”
result=“sqlException”/>
<exception-mapping exception=“java.lang.Exception”
result=“error”/>
</gboal-exception-mappings>
<action name=“dataAccess” class=“DataAccessAction”>
<exception-mapping exception=“cn.com.MyException”
result=“error”/>
<result>/dataAccess.jsp</result>
</action>
</package>
//当出现java.sql.SQLException异常将链接到/login.action
//当出现java.lang.Exception异常时将链接到/error.jsp
原文:http://blog.csdn.net/s2940086379/article/details/46038709