在Struts2应用中,对于未捕获的异常通常有两种处理方式,一是对于所有的Action进行捕获处理,一是对特定Action进行捕获处理。
对所有Action进行捕获
<package name="base" extends="struts-default">
<global-results>
<result name="securityerror">/securityerror.jsp</result>
<result name="error">/jsp/error.jsp</result>
</global-results>
<global-exception-mappings>
<exception-mapping
exception="org.apache.struts.register.exceptions.SecurityBreachException"
result="securityerror" />
<exception-mapping exception="java.lang.Exception"
result="error" />
</global-exception-mappings>
</package>
对特定的Action进行捕获
<action name="actionspecificexception" class="org.apache.struts.register.action.Register" method="throwSecurityException">
<exception-mapping exception="org.apache.struts.register.exceptions.SecurityBreachException"
result="login" />
<result>/register.jsp</result>
<result name="login">/login.jsp</result>
</action>