struts2异常页面配置《做参考》
2014-05-30 10:30
225 查看
今天处理了struts2 的异常,跟大家分享下:
1.处理不存在的Action:
只需在struts.xml中加
2.处理其他异常(如空指针,不存在的方法...),我们一般会定义全局异常及全局Result:
3.处理不存在的页面,如不存在的JSP,html,htm等页面(404异常),struts是不能处理这个异常的,还有其他异常(如500,401等等)都交给tomcat来处理,只需在web.xml中加如下配置即可:
1.处理不存在的Action:
只需在struts.xml中加
1 | < default-action-ref name = "defaultAction" /> |
2 | < action name = "defaultAction" class = "com.lsw.permission.action.DefaultAction" /> |
01 | <global-results><!-- 定义全局Result --> |
02 | <result name= "redirect" type= "redirect" >${returnPageURL}</result> |
03 | <result name= "dispatcher" type= "dispatcher" >${returnPageURL}</result> |
04 | <result name= "login" type= "dispatcher" >/login.jsp</result> |
05 | <result name= "exceptionError" type= "dispatcher" >/WEB-INF/jsp/error/exception.jsp</result> |
06 | </global-results> |
07 |
08 | <global-exception-mappings><!-- 全局异常处理 --> |
09 | <exception-mapping result= "exceptionError" exception= "java.lang.NullPointerException" /> |
10 | <exception-mapping result= "exceptionError" exception= "java.lang.NoSuchMethodException" /> |
11 | <exception-mapping result= "exceptionError" exception= "java.lang.Exception" /> |
12 | </global-exception-mappings> |
01 | <!-- 处理不存在的页面 --> |
02 | <error-page> |
03 | <error-code> 404 </error-code> |
04 | <location>/WEB-INF/jsp/error/ 404 .jsp</location> |
05 | </error-page> |
06 | <!-- 处理 500 异常 --> |
07 | <error-page> |
08 | <error-code> 500 </error-code> |
09 | <location>/WEB-INF/jsp/error/ 500 .jsp</location> |
10 | </error-page> |
相关文章推荐
- struts2 异常跳转页面配置
- Struts2配置异常:Exception starting filter struts2
- struts2配置导致jsp使用标签库异常的处理
- Struts2中action重定向跳转到jsp页面两种配置方式
- 登录成功或失败直接在当前页面给出提示信息,不必进行struts2的路由配置方案
- Struts2学习:配置篇之异常映射
- 配置404,错误页面异常页面及其页面打印错误代码
- web.xml配置了dispatcher FORWARD和REQUEST 导致页面不能接受Struts2中的属性值
- log4net 高级运用之:在页面级捕获可预见的异常,在全局应用程序类Global.asax中捕获未知的异常(更新log4net的样式和配置)
- 深入 Struts2 的配置 - 处理多个请求-处理请求结果-模型驱动-异常机制
- Struts2异常映射的配置
- Struts2实现文件上传,直接访问JSP页面出现异常
- Struts2中action重定向跳转到jsp页面两种配置方式
- struts2配置常见异常
- struts2的XML配置、动态方法调用、获取页面表单元素的方法
- struts2 的jsp页面中路径的配置
- web.xml配置struts2之后访问jsp页面报Http 404错误
- 于MyEclipse对Struts2配置文件较检异常 Invalid result location value/parameter
- struts2抛出异常自定义跳转页面
- JAVA_WEB Struts2学习:使用验证框架进行校验JSP页面元素 反编译工具的配置 Strtuts2 国际化学习