struts2配置全局异常拦截
把这段配置放到package中就行了....
<global-results><result name="commonErrorPage">/error.jsp</result></global-results><global-exception-mappings> <exception-mapping name="commonErrorPage" exception="java.lang.Exception" result="commonErrorPage"/> </global-exception-mappings>
<interceptors><interceptor name="exceptionInterceptor" /><interceptor-stack name="myStack"> <interceptor-ref name="defaultStack" /> <interceptor-ref name="exceptionInterceptor" /> </interceptor-stack></interceptors><default-interceptor-ref name="myStack" />
<bean id="ExceptionInterceptor"name="code">/** * 异常拦截器,将异常信息捕获,然后统一在异常信息页面进行显示处理 * @author..... * */public class ExceptionInterceptor extends AbstractInterceptor{ private static final long serialVersionUID = -973363922210992103L; public static final String EXCEPTION = "commonErrorPage"; @Override public String intercept(ActionInvocation invocation) throws Exception { try { return invocation.invoke(); } catch (Exception e) { ActionContext context = invocation.getInvocationContext(); StringWriter writer = new StringWriter(); e.printStackTrace(new PrintWriter(writer, true)); context.put("tipMessage", e.getMessage()); context.put("tipCourse", writer.toString()); return EXCEPTION; } }}