Struts 2 中的全局异常处理程序
我有一个混合 Struts 1 和 Struts 2 应用程序。我的 Struts 1 应用程序具有以下异常处理程序:
<global-exceptions>
<exception type="java.lang.Exception" handler="myClass" />
</global-exceptions>
<global-forwards>
<forward name="error" path="/error.jsp" module="/" />
</global-forwards>
我正在尝试在应用程序的 Struts 2 部分中完成类似的映射。这是我现在所拥有的:
<global-results>
<result name="myErrorHandler" type="redirectAction">
<param name="actionName">myErrorAction</param>
</result>
</global-results>
<global-exception-mappings>
<exception-mapping exception="java.lang.Exception" result="myErrorHandler" />
</global-exception-mappings>
<action name="myErrorAction" class="myErrorAction">
<result name="error">/error.jsp</result>
</action>
但是,每当我测试错误处理程序时,我都会遇到无限循环(myErrorAction 不断调用自身)。有没有更好的方法在 Struts 2 中设置全局异常处理程序?我的操作有自定义代码,它创建特殊的日志条目并构建错误消息以在 jsp 页面上向用户显示。
I have a hybrid Struts 1 and Struts 2 application. My Struts 1 application has the following exception handler:
<global-exceptions>
<exception type="java.lang.Exception" handler="myClass" />
</global-exceptions>
<global-forwards>
<forward name="error" path="/error.jsp" module="/" />
</global-forwards>
I'm trying to accomplish a similar mapping in my Struts 2 part of the application. Here is what I have right now:
<global-results>
<result name="myErrorHandler" type="redirectAction">
<param name="actionName">myErrorAction</param>
</result>
</global-results>
<global-exception-mappings>
<exception-mapping exception="java.lang.Exception" result="myErrorHandler" />
</global-exception-mappings>
<action name="myErrorAction" class="myErrorAction">
<result name="error">/error.jsp</result>
</action>
However, whenever I test out my error handler, I get an infinite loop (myErrorAction keeps calling itself). Is there a better way to setup a global exception handler in Struts 2? My action has custom code which creates special log entries and builds the error message to display to the user on the jsp page.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否 100% 确定您的
myErrorAction
(或您的error.jsp
)没有抛出异常?这将解释无限循环。人们应该非常小心,处理异常的资源在这方面是完全确定的。
Are you 100% sure that your
myErrorAction
(or yourerror.jsp
) is not throwing an Exception? That would account for the infinite loop.One should take much care that the resources that handle exceptions are totally sure in this regard.