Struts框架允许程序将异常抛给Struts框架。Struts框架可以处理抛出来的异常。
<action name="exceptionAction"class="com.action.ExceptionAction">
<exception-mapping exception="java.lang.ArithmeticException"
result="error_arith">exception-mapping>
<exception-mapping exception="java.io.FileNotFoundException"
result="error_notfound">exception-mapping>
<exception-mapping exception="java.lang.Exception"
result="error_exception">exception-mapping>
<result name="succ">/succ_exception.jspresult>
<result name="error_arith">/error_arith.jspresult>
<result name="error_notfound">/error_notfound.jspresult>
action>
<package name="default"namespace="/" extends="struts-default">
<global-results>
<result name="error_arith">/error_arith.jspresult>
<result name="error_notfound">/error_notfound.jspresult>
global-results>
<global-exception-mappings>
<exception-mapping exception="java.lang.ArithmeticException"
result="error_arith">exception-mapping>
<exception-mapping exception="java.io.FileNotFoundException"
result="error_notfound">exception-mapping>
<exception-mapping exception="java.lang.Exception"
result="error_exception">exception-mapping>
global-exception-mappings>
package>
<package name="other"namespace="/other" extends="default">
<action name="exceptionOtherAction" class="com.action.ExceptionOtherAction">action>
package>
web.xml中配置:
<error-page>
<error-code>404error-code>
<location>/xxx.jsplocation>
error-page>
<error-page>
<error-code>500error-code>
<location>/yyy.jsplocation>
error-page >