如何将异常从Struts 2中的其他动作全局地传递给单个动作 [英] How to pass exceptions globally to a single action from other actions in Struts 2

查看:51
本文介绍了如何将异常从Struts 2中的其他动作全局地传递给单个动作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将异常全局传递给名为 ErrorAction 的单个操作文件,例如 Index 操作.

I want to pass exceptions globally to a single action file called ErrorAction, say from Index action.

这是我的 struts.xml 文件:

Here's my struts.xml file:

<global-results>    
    <result name="myErrorHandler" type="redirectAction">    
        <param name="actionName">myError</param>
    </result>    
    <result name="login" type="tiles">
        login
    </result>    
</global-results>    

<global-exception-mappings>    
    <exception-mapping exception="java.lang.Exception" result="myErrorHandler" />    
</global-exception-mappings>    

<action name="myError" class="com.actions.ErrorAction">    
    <interceptor-ref name="exception" />    
    <interceptor-ref name="defaultStack" />    
    <result name="error" type="tiles">error</result>    
</action>   

....    

<action name="Index" class="com.actions.Index">    
    <interceptor-ref name="defaultStack" />    
    <result name="success" type="tiles">home</result>    
</action>

推荐答案

exception 拦截器已包含在 defaultStack 中.使用自定义堆栈,以便将应用程序未捕获的任何异常记录下来,然后由全局异常映射处理

The exception interceptor is already included in the defaultStack. Use the custom stack so that any exceptions not caught by the application will be logged and then handled by the global exception mapping

<interceptors>
  <interceptor-stack name="appDefaultStack">
    <interceptor-ref name="defaultStack">
      <param name="exception.logEnabled">true</param>
      <param name="exception.logLevel">ERROR</param>
    </interceptor-ref>
  </interceptor-stack>
</interceptors>
<default-interceptor-ref name="appDefaultStack" />

这篇关于如何将异常从Struts 2中的其他动作全局地传递给单个动作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆