How to define a global page when requested page or method is not found?(找不到请求的页面或方法时如何定义全局页面?)
问题描述
我知道如何在遇到异常时在我们定义的包中调整全局错误重定向页面,只需在 struts.xml 的父包中添加以下配置:
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:
- 当动作配置未知时
- 当找不到操作和结果代码的结果时
- 找不到操作方法时
这篇关于找不到请求的页面或方法时如何定义全局页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:找不到请求的页面或方法时如何定义全局页面?
基础教程推荐
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
