struts2中错误处理
定义一个 package,然后其他package都继承 这个package
struts-global
就 有了这个错误处理功能了
然后再自己写个类
struts.xml
<constant name="struts.devMode" value="true" />
<constant name="struts.enable.DynamicMethodInvocation" value="false"></constant>
<!-- <constant name="struts.custom.i18n.resources" value="itcast"></constant> -->
<package name="struts-global" namespace="/" extends="struts-default">
<global-results>
<result name="errHandler" type="chain">
<param name="actionName">errorProcessor</param>
</result>
</global-results>
<global-exception-mappings>
<exception-mapping result="errHandler" exception="java.lang.Exception">
</exception-mapping>
</global-exception-mappings> <action name="errorProcessor" class="cn.itcast.sh.error.ErrorProcess"> <result>error.jsp</result>
</action>
</package>
cn.itcast.sh.error.ErrorProcess类
package cn.itcast.sh.error; import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport; public class ErrorProcess extends ActionSupport {
private Exception exception; public Exception getException() {
return exception;
} public void setException(Exception exception) {
this.exception = exception;
}
@Override
public String execute()
{
ActionContext.getContext().getValueStack().push(this.exception.getMessage());
return this.SUCCESS;
}
}
其他 strut.xml中
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<package name="user" namespace="/" extends="struts-global">
<action name="UserAction_*" method="{1}" class="cn.itcast.sh.action.UserAction">
<result name="userList">/user/list.jsp</result>
</action> </package>
</struts>
struts2中错误处理的更多相关文章
- struts2中错误提示:There is no Action mapped for namespace / and action name
当在struts2中运行时出现如上所述错误时: 1.在src目录下创建struts.xml一定要注意拼写 2.struts.xml文件中引入和extend是否正确 3.在web.xml 中<we ...
- struts2中错误There is no Action mapped for namespace [/] and action name [] associated with context path
1 There is no Action mapped for namespace [/] and action name [] associated with context path [/Stru ...
- struts2中各个jar包作用
Struts2.3.4 所需的Jar包及介绍 Jar包的分类 jar包名称 jar包版本 jar包 文件名 jar包 的作用 jar包内包含的主要包路径及主要类 依赖的自有jar包名称 依赖的第三方j ...
- struts2中的jar包
核心包: (后面数字是版本号,不同struts2版本,数字可能不一样.) struts2-core-2.1.8.1 struts2的核心jar包,不可缺少的 xwork-core-2.1.6 xwor ...
- 简单理解Struts2中拦截器与过滤器的区别及执行顺序
简单理解Struts2中拦截器与过滤器的区别及执行顺序 当接收到一个httprequest , a) 当外部的httpservletrequest到来时 b) 初始到了servlet容器 传递给一个标 ...
- Struts2中<jsp:forward page="xxx.action"></jsp:forward>失效
问题:在Struts2中<jsp:forward page="xxx.action"></jsp:forward>失效了,不但调转不过去还报404错误.不知 ...
- 【转】Struts2中的MethodFilterInterceptor(转)
这是一个Struts2.1.8.1应用,代码如下 首先是web.xml文件 view plaincopy to clipboardprint?01.<?xml version="1.0 ...
- struts2中constant参数设置
序号 方法 说明 1 <constant name="struts.i18n.encoding" value="UTF-8"/> 指定web应用默认 ...
- struts2中的常量
struts2中的常量: 在:struts2-core-2.1.8.1\org\apache\struts2\default.properties 文件里 <!-- 配制i18n国际化--> ...
随机推荐
- 配置Tomcat的服务端口
- 3、Spring整合Hibernate
经过前面的两节分析:1.Hibernate之生成SessionFactory源码追踪 和 2.Spring的LocalSessionFactoryBean创建过程源码分析 .我们可以得到这样一个结论, ...
- android程序获取WIFI的IP地址和MAC地址
转自:http://my.oschina.net/chenj/blog/68680 近日在鼓捣这玩意,拿出来大家分享一下,代码比较简单,如果有不懂的再问 <Button android:id=& ...
- ubuntu安装postgresql与postgis
版本信息 ubuntu 14.04.1LTS postgresql 9.3.5 postgis 2.1.2 今天尝试着安装了postgis 2.1.2,(较简便的包安装,不是源码 ...
- [android警告] AndroidManifest.xml警告 Should explicitly set android:allowBackup to true or false
http://www.cnblogs.com/javadu/p/3812528.html Android中AndroidManifest.xml警告 Should explicitly set and ...
- USACO Section 3.3: Home on the Range
到最后发现是DP题 /* ID: yingzho1 LANG: C++ TASK: range */ #include <iostream> #include <fstream> ...
- delphi常用函数
直接引用了 http://www.cnblogs.com/doit8791/archive/2012/05/17/2507073.html.
- python lambda函数详细解析(面试经常遇到)
1 作用:通常是用来在python中创建匿名函数的 2 格式: lambda 参数[,参数] : 表达式 3 注意: (1)lambda定义的是单行函数, 如果需要复杂的函数,应该定义普通函数 (2) ...
- [原]poj-2488-water-DFS
题目大意: 输入一个p*q的棋盘, 行用数字表示, 列用大写字母表示 , 1 <= p*q <= 26, 输出能够把棋盘全部空格走完且每个空格只走一次的字典序最小的路径.不存在则输出“im ...
- linux/shell 文本文件删除/删掉空行
分别用sed awk perl grep 实现: sed '/^$/d' input.txt > output.txt #output file: output.txt sed -i '/^$/ ...