systemexceptionhandler.java
来自「这是一个jbpm的高级应用,是一个oa工作流的系统,里面用到了spring,hi」· Java 代码 · 共 76 行
JAVA
76 行
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.log4j.Logger;
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.managers.SystemException;
/**
* 通用异常处理器
* @author Administrator
*
*/
public class SystemExceptionHandler extends ExceptionHandler {
//直接使用Log4j的API
//private static Logger logger = Logger.getLogger(SystemExceptionHandler.class);
//使用commons-log来记录日志
private static Log logger = LogFactory.getLog(SystemExceptionHandler.class);
@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();
}
//打印异常消息
ex.printStackTrace();
logger.error(ex.getMessage(), ex);
if(ex instanceof SystemException){
SystemException se = (SystemException)ex;
//取出key值
String key = se.getKey();
//创建异常消息
ActionMessage error = null;
if(key == null){
//ae.getKey() = errors.detail
error = new ActionMessage(ae.getKey(),se.getMessage());
}else{
error = new ActionMessage(key);
}
//将异常消息保存到request中
storeException(request, key, error, forward, "request");
//不再做处理,直接返回错误页面
return forward;
}
return super.execute(ex, ae, mapping, formInstance, request, response);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?