Struts2 global-results(全局结果)+异常映射 Results结果类型
来源:互联网 发布:手机电流测试软件 编辑:程序博客网 时间:2024/04/28 02:07
global-results+异常映射,实现,报错,跳转指定页面
在Action中execute方法的方法签名为public String execute() throws Exception,这样,Action可以抛出任何Exception,那么,Exception抛给谁呢?
- 实验
public String execute() throws Exception { int a = 5/0; return this.SUCCESS; } 上面的代码中有int a=5/0;,很显然,会抛出除数为0的错误,这个错误是RuntimeException,我们的程序没有进行相应的例外处理,则会抛给Struts2去处理。可见,这个错误直接被抛给了web容器,Struts2并没有处理。那么,在实际的项目中很显然不能这么简单而粗暴的处理错误,一种简单的处理方法就是跳转到一个错误处理页面。
使用异常机制
<package name="sd" extends="struts-default" namespace="/"> <global-results> <result name="error">error.jsp</result> </global-results> <!-- 异常映射 --> <global-exception-mappings> <!--result 映射对应的值,通过它来,决定调取那个 全局结果,exception 被抓取的报错类型 --> <exception-mapping result="error" exception="java.lang.Exception"/> </global-exception-mappings> <action name="struts_test" class="com.struts.one.test.Struts_Test_One" > <!-- action 执行方法 返回结果, 返回的字符串,然后匹配对应的返回结果 --> <result name="math-exception">succeed.jsp</result> </action></package>
阅读全文
0 0
- Struts2 global-results(全局结果)+异常映射 Results结果类型
- Struts2 全局结果类型<global-results>
- struts2异常处理,global-results定义全局结果处理
- struts2异常处理,global-results定义全局结果处理
- Struts2全局结果集Global Results
- Struts2-全局结果集global-results
- struts2全局结果集global-results
- Struts2的Global Results全局结果集
- struts 2 global-results 全局结果集
- struts2_08_global-results(全局结果集)
- Struts2(七)global-results 和 extends 和动态结果集详解
- 全局result(global-results)
- global-results in struts2
- struts2的global-results
- Confluence 查找结果(Search Results)宏
- struts2: include和global-results
- struts2: include和global-results
- struts2的配置文件global-results
- Scales
- linux中的NFS文件共享服务
- Playing with Numbers Kattis
- 【POJ】2376
- 巧用Ajax的beforeSend 提高用户体验
- Struts2 global-results(全局结果)+异常映射 Results结果类型
- sql优化的几种方法
- POJ 1050 To the Max
- 7z的资源管理器右键菜单缺失
- Bigdata Development Web_Study_04(Session和Cookie)
- Color the ball||HDU1556
- dubbo配置方式(下)
- 编译错误:Failed to save the updated manifest to the file ..........
- [opengl笔记]2017年8月17日