`
henghengdh
  • 浏览: 153568 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

(Struts2)在将Global Exception Redirect到一个Action后,如何在Action中获取该Exception5

 
阅读更多
(Struts2)在将Global Exception Redirect到一个Action后,如何在Action中获取该Exception5
我们知道在struts.xml中增加global-exceptions配置可以将未捕捉的异常指向一个result,且该result可显示一个jsp页面,在jsp页面中用<s:property value="exception.name"/>等可以显示该异常消息。
但是因为我希望在显示异常前做一些额外处理,比如发送Email通知维护人员。所以我将result redirect到一个Action中,但是如何在该Action中获得捕捉到的异常?
我使用了:
1.  ActionContext.getContext().getValueStack().findValue("exception");
2.  ActionContext.getContext().getParameters.get("exception");
3.  ActionContext.getContext().get.....
等等方法都无法获得该Exception.

用chain 类型的action,chain类型可以把栈中的值也传递过去。
这样能够把发生的异常传递到你指定的类,在做处理。
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics