- 浏览: 154563 次
- 性别:
- 来自: 上海
文章分类
最新评论
-
jiangyeqt:
好好的温习了一遍,讲的非常的到位
Session的原理 -
JAVA静静:
这是什么啊?有没有源码?看不懂诶!
开源框架Pushlet入门 -
colinzhy:
讲的很深刻,学习了
Session的原理 -
昔雪似花:
...
Map-iterator -
不相信眼泪:
恩,很好,多谢
.scc文件是做什么用的?
1 自定义异常类 SystemException.java
public class SystemException extends RuntimeException{
//自定义key
private String key;
//自定义参数
private Object[] values;
//实现父类的构造方法
public SystemException() {
super();
}
public SystemException(String message, Throwable cause) {
super(message, cause);
}
public SystemException(String message) {
super(message);
}
public SystemException(Throwable cause) {
super(cause);
}
//自定义构造方法
public SystemException(String message, String key) {
super(message);
this.key=key;
}
//自定义构造方法,带一个参数
public SystemException(String message, String key,Object value) {
super(message);
this.key=key;
this.values=new Object[]{value};
}
//自定义构造方法,带多个参数
public SystemException(String message, String key,Object[] values) {
super(message);
this.key=key;
this.values=values;
}
//相应的get方法
public String getKey() {
return key;
}
public Object[] getValues() {
return values;
}
}
2 自定义异常处理器 SystemExceptionHandler.java
//作用:截获SystemException,并根据SystemException中的信息动态创建ActionMessage等这些错误信息,
将其存在request中
public class SystemExceptionHandler extends ExceptionHandler{
/**
* 处理SystemException异常
*/
@Override
public ActionForward execute(Exception ex,//抛出的异常
ExceptionConfig config,//struts-config.xml中的配置信息
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws ServletException {
ActionForward forward=null;
//创建ActionForward
if(config.getPath()!=null){
//有path属性,则根据path创建
forward=new ActionForward(config.getPath());
}else {
//没有path属性,则根据input属性创建
forward=mapping.getInputForward();
}
if(ex instanceof SystemException){
SystemException se=(SystemException)ex;
//key可有可无,所以取出key进行判断
String key=se.getKey();
ActionMessage error=null;
//如果自定义的key为空,用struts的
if(key==null){
//拿出error.default和message,创建ActionMessage对象
error=new ActionMessage(config.getKey(),se.getMessage());
}else {
//如果自定义的key有值
if(se.getValues()!=null){
error=new ActionMessage(key,se.getValues());
}else {
//如果自定义的key有值,则根据key创建ActionMessage对象
error=new ActionMessage(key);
}
}
//将这个ActionMessage放到request中。key为自定义的,error为ActionMessage对象
//forward是要转到什么地方,根据path属性创建。"request"为scope的一个,也可以
//用config.getScope()
this.storeException(request, key, error, forward, config.getScope());
return forward;
}
return super.execute(ex, config, mapping, form, request, response);
}
}
3 编写配置文件 struts-config.xml
<global-exceptions>
<exception key="error.default"
type="java.lang.Exception"
scope="request"
path="/common/exception.jsp"
<!-- 自定义的异常处理类 -->
handler="org.oa.common.SystemExceptionHandler"/>
</global-exceptions>
4 编写资源文件 ApplicationResources.properties
error.default={0}
error.org.del=Can't Del Orgnation,id is {0}!
5 业务代码
throw new org.oa.common.SystemException("存在子机构,不允许删除!","error.org.del",org.getOname());
发表评论
-
[导入]为Struts 2.0做好准备
2009-10-29 19:00 351摘要: Struts 2.0系列之一 Struts ... -
[导入]常用的Struts 2.0的标志(Tag)介绍
2009-10-29 19:00 579摘要: 在上一篇文章《为Struts 2.0做好准备 ... -
[导入]Struts 2.0的Action讲解
2009-10-29 19:00 466摘要: 有Struts 1.x经验的朋友都知道Act ... -
[导入]在Struts 2.0中国际化(i18n)您的应用程序
2009-10-29 19:00 325摘要: Struts 2.0系列之四 国际化是商业系 ... -
[导入]转换器(Converter)——Struts 2.0中的魔术师
2009-10-29 19:00 536摘要: 在我已往的Struts 1.x项目经验中,有 ... -
[导入]在Struts 2.0中实现表单数据校验(Validation)
2009-10-29 19:00 580摘要: All Input Is Evil! ... -
[导入]Struts 2的基石——拦截器(Interceptor)
2009-10-29 19:00 307摘要: Struts 2.0系列之七 Interce ... -
[导入]在Struts 2中实现IoC
2009-10-29 19:00 752摘要: Struts 2.0系列之八 IoC(Inv ... -
[导入]在Struts 2中实现文件上传
2009-10-29 19:00 594摘要: Struts 2.0系列之九 Struts ... -
[导入]在Struts 2中实现CRUD
2009-10-29 19:00 276摘要: Struts 2系列之十 CRUD是Crea ... -
[导入]Struts 2中的OGNL
2009-10-29 19:00 659摘要: Struts 2系列之十一 OGNL是一种功 ... -
[导入]Strus 2的新表单标志的使用
2009-10-29 19:00 343摘要: Struts 2系列之十二 Struts 2 ... -
[导入]Struts 2与AJAX(第一部分)
2009-10-29 19:00 450摘要: Struts 2系列之十三 在当今——Web ... -
[导入]Struts 2与AJAX(第二部分)
2009-10-29 19:00 498摘要: Struts 2系列之十四 在上一篇文章《S ... -
[导入]Struts 2与AJAX(第三部分)
2009-10-29 19:00 636摘要: 在上两部分的《Struts 2与AJAX》中 ... -
struts2 页面转向错误No result defined for action and result Invalidation
2009-11-20 16:57 711Messages: No result defined for ... -
struts1.3-基础及原理
2009-11-29 22:59 658网站struts.apache.org 实践 ... -
struts1.3-DispatchAction
2009-11-30 08:10 589DynaActionForm 配态form 1 配置动态for ... -
struts1.3-Converter
2009-11-30 08:10 710Converter添加java.util.Date ... -
struts1.3-exception
2009-11-30 08:11 718一 配置异常(在struts-config.xml文件中定义) ...
相关推荐
struts2-core-2.0.1.jar, struts2-core-2.0.11.1.jar, struts2-core-2.0.11.2.jar, struts2-core-2.0.11.jar, struts2-core-2.0.12.jar, struts2-core-2.0.14.jar, struts2-core-2.0.5.jar, struts2-core-2.0.6.jar,...
struts2-spring-plugin-2.3.15.2.jar ; struts2-json-plugin-2.3.16.3.jarstruts2-spring-plugin-2.3.15.2.jar ; struts2-json-plugin-2.3.16.3.jar
struts2-config-browser-plugin-2.3.24.jar, struts2-core-2.3.24.jar, struts2-jasperreports-plugin-2.3.24.jar, struts2-jfreechart-plugin-2.3.24.jar, struts2-pell-multipart-plugin-2.3.24.jar, struts2-...
Struts1.3的全部架包,非常全,包含:struts-core-1.3.10.jar,struts-tiles-1.3.10.jar,struts-taglib-1.3.10.jar,struts-faces-1.3.10.jar,struts-extras-1.3.10.jar........
赠送jar包:struts2-json-plugin-2.3.24.jar; 赠送原API文档:struts2-json-plugin-2.3.24-javadoc.jar; 赠送源代码:struts2-json-plugin-2.3.24-sources.jar; 赠送Maven依赖信息文件:struts2-json-plugin-...
struts-core-1.3.10.jar, struts2-cdi-plugin-2.3.30.jar, struts2-codebehind-plugin-2.3.30.jar, struts2-config-browser-plugin-2.3.30.jar, struts2-convention-plugin-2.3.30.jar, struts2-core-2.3.30.jar, ...
struts2-json-plugin,Struts JSON插件
struts2-ssl-plugin-1.2.1.jar
struts2-core-2.2.3.1-sources.jar struts2-core-2.2.3.1-sources.jar struts2-core-2.2.3.1-sources.jar
struts-config.xml配置文件对学struts的人必备的查找资料。
struts2-core-2.5.18.jar包下载,支持struts2的类库下载
最新struts2-struts1-plugin-2.1.8.1.jar
struts2-dojo-plugin-2.3.4 jar 日期控件的jar包 需要的自行下载
struts2-convention-plugin-2.3.32
struts2-dojo 跨域时解决拒绝访问的问题
struts2-showcase.rar struts2自带的源码例子
struts2-convention-plugin-2.3.24.1
struts2-dojo-plugin-2.2.1.jar, 直接导入到Struts2项目里即可,注意版本。
struts2-convention-plugin-2.3.15.1.jar
hamcrest-core-1.3.jar, jackson-annotations-2.6.0.jar, jackson-core-2.6.1.jar, jackson-databind-2.6.1.jar, javassist-3.20.0-GA.jar, jcl-over-slf4j-1.7.6.jar, json-lib-2.3-jdk15.jar, juli-6.0.18.jar, ...