2008-07-16
统一异常处理
package com.bjsxt.oa.manager;
public class SystemException extends RuntimeException {
//异常代码
private String key;
private Object[] values;
public SystemException() {
super();
}
public SystemException(String message, Throwable throwable) {
super(message, throwable);
}
public SystemException(String message) {
super(message);
}
public SystemException(Throwable throwable) {
super(throwable);
}
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;
}
public String getKey() {
return key;
}
public Object[] getValues() {
return values;
}
}
<global-exceptions> <exception key="errors.detail" type="java.lang.Exception" path="/common/exception.jsp" scope="request" handler="com.bjsxt.oa.web.SystemExceptionHandler" ></exception> </global-exceptions>
package com.bjsxt.oa.web;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ExceptionHandler;
import org.apache.struts.config.ExceptionConfig;
import com.bjsxt.oa.manager.SystemException;
public class SystemExceptionHandler extends ExceptionHandler {
private static Log logger = LogFactory.getLog(SystemExceptionHandler.class);
/**
* 处理SystemException异常
*/
@Override
public ActionForward execute(
Exception ex,
ExceptionConfig ae,
ActionMapping mapping,
ActionForm formInstance,
HttpServletRequest request,
HttpServletResponse response) throws ServletException {
ActionForward forward = null;
if(ae.getPath() != null){
forward = new ActionForward(ae.getPath());
}else{
forward = mapping.getInputForward();
}
logger.debug("出现异常", ex);
//ex.printStackTrace();
if(ex instanceof SystemException){
SystemException se = (SystemException)ex;
//取出key值
String key = se.getKey();
ActionMessage error = null;
if( key == null){
error = new ActionMessage(ae.getKey(),se.getMessage());
}else{
if(se.getValues() != null){
error = new ActionMessage(key,se.getValues());
}else{
error = new ActionMessage(key);
}
}
this.storeException(request, key, error, forward, ae.getScope());
return forward;
}
return super.execute(ex, ae, mapping, formInstance, request, response);
}
}
if(org.getChildren().size() > 0){
throw new SystemException("存在子机构,不允许删除","exception.org.del",org.getId());
}
发表评论
- 浏览: 30485 次
- 性别:

- 来自: 大连

- 详细资料
搜索本博客
我的相册
strutsWorkflow
共 3 张
共 3 张
最近加入圈子
链接
- 冰封太子
- 个人博客
- eclipse-API 函数
- eclipse-SWT资源
- Eclipse-下载
- hibernate-官方网站
- html-教程与代码
- html-教程与代码
- html-蓝色理想
- html-语言教程
- Javascript-基础教程
- PowerDesigner视频
- 流星絮语 JAVA学习笔记
- AppServNetword
- JDBC、SQLJ 的Oracle 驱动
- BeanSoft's Java Blog
- 面试时候经常会问的一些问题(不断补充中)
- Hibernate 3入門
- java学习
- 上帝的笔记本
- xiao
- 视频
- 尚学堂
- Intellij Idea下的iBatis
- vssplugin
- XDoclet最新下载包
- prototype.js官方
- 在线视频
- Ruby
- Aptana Studio
- 面试题集合
- 徐风城
- 最好的java源码
- java blog
最新评论
-
JSP购物车实例讲解
能不能写写struts2做成的购物车模块,把购物车放在session里面?
-- by chucai -
Struts 源码学习之Action ...
initChain()真是看不明白用了Commons Chain来搞了个CoR模 ...
-- by dvdface -
IntelliJ IDEA使用技巧一 ...
学习了!
-- by ziscloud -
ssh分页实例
else if ("next".equals(state)) 可以无止境的n ...
-- by figeonline -
js应用
这文章说什么的啊?能不能给个效果图啊?晕哎
-- by zhangzldipan






评论排行榜