Struts中的全局异常处理程序2 [英] Global Exception Handler in Struts 2
问题描述
< global-exceptions>
< exception type =java.lang.Exceptionhandler =myClass/>
< / global-exceptions>
<全局转发>
< forward name =errorpath =/ error.jspmodule =//>
< / global -forward>
我正在尝试在我的Struts 2部分应用程序中完成类似的映射。这是我现在所在:
< global-results>
< result name =myErrorHandlertype =redirectAction>
< param name =actionName> myErrorAction< / param>
< / result>
< / global-results>
< global-exception-mappings>
< exception-mapping exception =java.lang.Exceptionresult =myErrorHandler/>
< / global-exception-mappings>
< action name =myErrorActionclass =myErrorAction>
< result name =error> /error.jsp< / result>
< / action>
然而,每当我测试我的错误处理程序,我得到一个无限循环(myErrorAction不断调用自己) 。有没有更好的方法在Struts 2中设置全局异常处理程序?我的操作有自定义代码,它创建特殊的日志条目,并构建错误消息以在jsp页面上向用户显示。
您是否确定您的 myErrorAction
(或您的 error.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.
Are you 100% sure that your myErrorAction
(or your error.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.
这篇关于Struts中的全局异常处理程序2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!