当没有找到请求的页面或方法时如何定义全局页面? [英] How to define a global page when requested page or method is not found?
问题描述
我知道如何通过在 struts.xml
中的父程序包中添加以下配置的异常遇到异常时,如何处理定义的程序包中的全局错误重定向页: / p>
I know how to fine a global error redirect page in our defined package when exception encountered that just by adding the following configuration in the parent package in struts.xml
:
<global-results>
<result name="error">/error.jsp</result>
</global-results>
<global-exception-mappings>
<exception-mapping exception="java.lang.Exception" result="error" />
</global-exception-mappings>
但是似乎无法捕获所请求的资源,方法,页面等异常,我的意思是如何捕获struts2级别的错误,然后我可以做一些处理它。
But It seems to not able to catch those exceptions like requested resources, methods, pages are not found, I mean how to catch the struts2-level errors, and then I can do something to handle it.
推荐答案
你应该定义你的 struts.xml
中的未知处理程序。当执行未知的动作,结果或方法时,框架会调用未知的处理程序。
You should define your unknown handler in the struts.xml
. Unknown handlers are called by the framework, when an unknown action, result, or method are executed.
<bean type="com.opensymphony.xwork2.UnknownHandler" name="handler" class="com.package.SomeUnknownHandler"/>
该类应该实现 UknownHandler
接口来处理案例:
The class should implement UknownHandler
interface to handle the cases:
- 当一个动作配置未知
- 当一个结果不能被找到行动和结果代码
- 无法找到动作方式
这篇关于当没有找到请求的页面或方法时如何定义全局页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!