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国际化--> ...
随机推荐
- 8 Types Of Friends You Need To Have in Your Life
8 Types Of Friends You Need To Have in Your Life一生中应该有的8种类型的朋友Did you know that people without frien ...
- Qt中的键盘事件,以及焦点的设置(比较详细)
Qt键盘事件属于Qt事件系统,所以事件系统中所有规则对按键事件都有效.下面关注点在按键特有的部分: focus 一个拥有焦点(focus)的QWidget才可以接受键盘事件.有输入焦点的窗口是活动窗口 ...
- SSM整合配置
SSM三大框架整合详细教程(Spring+SpringMVC+MyBatis) 使用SSM(Spring.SpringMVC和Mybatis)已经有三个多月了,项目在技术上已经没有什么难点了,基于现有 ...
- Oracle 全文索引相关命令
--用sys用户登录,解锁ctxsys用户alter user ctxsys account unlock; --授权给对应用户grant execute on ctx_ddl to yw; --用y ...
- WPF多线程UI更新——两种方法
WPF多线程UI更新——两种方法 前言 在WPF中,在使用多线程在后台进行计算限制的异步操作的时候,如果在后台线程中对UI进行了修改,则会出现一个错误:(调用线程无法访问此对象,因为另一个线程拥有该对 ...
- 使用struts taglib导致java.lang.NullPointerException: Module 'null' not found.
比如说,只要jsp的代码里有<html:....>或者<bean:...>之类的struts标签就会在访问该jsp页面的时候报这个错 最后参考这篇文章,发现原来是因为web.x ...
- SNMP SNMP协议
SNMP协议 一.什么是SNMP? SNMP是简单网络管理协议[Simple Network Management Protocol],由一组网络管理的标准组成,包含一个应用层协议(applicati ...
- cmd执行mssql脚本或者执行mysql脚本
private static int ExecuteMSSql(DbInfo db, string sqlPath) { Console.WriteLine("=============== ...
- 【Tech】YCSB-0.1.3安装使用
1. 下载YCSB 0.1.3: wget https://github.com/brianfrankcooper/YCSB/archive/0.1.3.tar.gz 如果提示“wget:命令没找到” ...
- springmvc 中常用的注解配置使用说明
很久没有用springmvc了,今天复习了一下,然后记录一下总结. @Controller 使用 @Controller 注释对将成为 MVC 中控制器的类进行注释并处理 HTTP 请求. @ ...