关于Struts2处理全局异常和局部异常:
struts.xml配置文件:<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<!--
1、禁用动态方法调用
,这些参数的默认值可以在struts2-core-2.1.8.1.jar/org.apache.struts2/default.properties中查看
-->
<constant name="struts.enable.DynamicMethodInvocation" value="true" />
<!-- 2、struts.devMode是否设置为开发模式 -->
<constant name="struts.devMode" value="true" />
<package name="test" namespace="/test" extends="struts-default">
<!--3、全局返回结果 -->
<global-results>
<result name="globalException">/WEB-INF/pages/globalException.jsp</result>
</global-results>
<!-- 4、全局异常 -->
<global-exception-mappings>
<exception-mapping result="globalException" exception="java.lang.Exception"></exception-mapping>
</global-exception-mappings>
<action name="exceptionaction" class="com.demo.ExceptionAction">
<!--5、配置局部的IOException -->
<exception-mapping result="partException" exception="java.io.IOException"></exception-mapping>
<!--6、测试返回 ftl 类型的页面 -->
<result name="success" type="freemarker">/WEB-INF/pages/success.ftl</result>
<result name="partException">/WEB-INF/pages/partexception.jsp</result>
</action>
<action name="*">
<result>/{1}.jsp</result>
</action>
</package>
</struts>
参数详解:
1、<global-result>标签:返回全全局通用的展现的视图,或者当出现异常是的处理途径
2、<exception-mapping>标签:result表示需要返回的结果视图,exception:需要捕获的异常类型,当Action中抛出异 常异常时在局部无法处理异常的时候就寻找全局异常来捕获该异常。
3、<result>标签中type属性可以设置返回页面的类型,在该处返回类型为.ftl。
自己做的小demo,先存起来以后兴许会用到吧,希望朋友们多多指教!!!
分享到:
相关推荐
struts2 ,struts2 demo,源代码示例
Struts2异常处理机制
Struts demo2
Struts2Demo2
struts2的异常处理,解决异步请求时,异常以json格式发送到客户端。以及dao单元测试的配置。
struts2中文乱码的解决DEMO,绝对可以运行。
这是一个struts2框架的处理流程的demo,里面有struts2基本的配置和模拟登录的例子,以及struts2前台后后台的数据交互方式的解释,代码中有完整的注释帮助理解struts2的基本流程,同时对jstl和struts2的标签也有一定...
Struts2和JSON交互的例子,非常容易理解,Struts2和JSON交互的例子,非常容易理解。
配合博文:http://blog.csdn.net/u011638419/article/details/41343683
Struts2+Excel导出Demo,测试可用带全部运行所需的JAR包
Struts示例demo
spring mybatis struts2的一个框架整合,列出主要代码
本文档主要介绍了struts2的异常处理机制,希望对你有所帮助。
基于struts2的博客网站Demo(自己学习),只是想从公司带回去~~
Struts2与Spring整合的demo
struts2练习,小demo,自己保存起来帮助以后也许有用,可以经常练习一下
struts 2整合urlwrite 4 demo
搭建一个简单的struts2开发环境 开发Struts2应用最少需要的JAR: a. struts2-core-2.x.x.jar : Struts2 框架的核心类库 b. xwork-core-2.x.x.jar: XWork类库,Struts2在其上构建 c. ognl-2.6.x.jar: 对象图导航...