在默认配置中
<interceptor-stack name="defaultStack">
<interceptor-ref name="exception"/>
<interceptor-ref name="alias"/>
<interceptor-ref name="servlet-config"/>
<interceptor-ref name="prepare"/>
<interceptor-ref name="i18n"/>
<interceptor-ref name="chain"/>
<interceptor-ref name="debugging"/>
<interceptor-ref name="model-driven"/>
<interceptor-ref name="fileUpload"/>
<interceptor-ref name="static-params"/>
<interceptor-ref name="params"/>
<interceptor-ref name="conversionError"/>
<interceptor-ref name="validation">
<param name="excludeMethods">input,back,cancel,browse</param>
</interceptor-ref>
<interceptor-ref name="workflow">
<param name="excludeMethods">input,back,cancel,browse</param>
</interceptor-ref>
</interceptor-stack>
可以看到,默认栈已经将exception拦截器加入了。而且是第一级拦截器。一个例子
<!DOCTYPE xwork PUBLIC "-//OpenSymphony Group//XWork 1.1.1//EN" "http://www.opensymphony.com/xwork/xwork-1.1.1.dtd">
<xwork>
<include file="webwork-default.xml" />
<package name="myaction" extends="webwork-default">
<default-action-ref name="myaction" />
<global-results>
<result name="xxx">error.jsp</result>
</global-results>
<global-exception-mappings>
<exception-mapping result="xxx"
exception="java.lang.RuntimeException"></exception-mapping>
</global-exception-mappings>
<action name="my" class="action.MyAction">
<result>MyJsp.jsp</result>
</action>
</package>
</xwork>
action的执行体中
throw new RuntimeException("异常了!");强制抛出了异常
exception属性用于设置该异常映射的异常类型。
result表示此action出现该异常时,系统将会进入哪个result.
在视图中(jsp),通过
<ww:property value="exception"/>,来输出异常实际类型和异常消息,如例子,acton出现了java.lang.RuntiemException,那么会显示
java.lang.RuntimeException: 异常了!
而<s:property value="exceptionStack" />则是打印出完整的堆栈
上面配置的是全局的,局部的需要在action元素中配置<exception-mapping result="" exception=""></exception-mapping>,acton中配置的异常处理会覆盖到全局异常影射中相同的异常类型
<interceptor-stack name="defaultStack">
<interceptor-ref name="exception"/>
<interceptor-ref name="alias"/>
<interceptor-ref name="servlet-config"/>
<interceptor-ref name="prepare"/>
<interceptor-ref name="i18n"/>
<interceptor-ref name="chain"/>
<interceptor-ref name="debugging"/>
<interceptor-ref name="model-driven"/>
<interceptor-ref name="fileUpload"/>
<interceptor-ref name="static-params"/>
<interceptor-ref name="params"/>
<interceptor-ref name="conversionError"/>
<interceptor-ref name="validation">
<param name="excludeMethods">input,back,cancel,browse</param>
</interceptor-ref>
<interceptor-ref name="workflow">
<param name="excludeMethods">input,back,cancel,browse</param>
</interceptor-ref>
</interceptor-stack>
可以看到,默认栈已经将exception拦截器加入了。而且是第一级拦截器。一个例子
<!DOCTYPE xwork PUBLIC "-//OpenSymphony Group//XWork 1.1.1//EN" "http://www.opensymphony.com/xwork/xwork-1.1.1.dtd">
<xwork>
<include file="webwork-default.xml" />
<package name="myaction" extends="webwork-default">
<default-action-ref name="myaction" />
<global-results>
<result name="xxx">error.jsp</result>
</global-results>
<global-exception-mappings>
<exception-mapping result="xxx"
exception="java.lang.RuntimeException"></exception-mapping>
</global-exception-mappings>
<action name="my" class="action.MyAction">
<result>MyJsp.jsp</result>
</action>
</package>
</xwork>
action的执行体中
throw new RuntimeException("异常了!");强制抛出了异常
exception属性用于设置该异常映射的异常类型。
result表示此action出现该异常时,系统将会进入哪个result.
在视图中(jsp),通过
<ww:property value="exception"/>,来输出异常实际类型和异常消息,如例子,acton出现了java.lang.RuntiemException,那么会显示
java.lang.RuntimeException: 异常了!
而<s:property value="exceptionStack" />则是打印出完整的堆栈
上面配置的是全局的,局部的需要在action元素中配置<exception-mapping result="" exception=""></exception-mapping>,acton中配置的异常处理会覆盖到全局异常影射中相同的异常类型