struts.xml:
<interceptors>
<interceptor name="exception" class="com.opensymphony.xwork.interceptor.ExceptionMappingInterceptor"></interceptor>
<interceptor name="exceptionInceptor" class="com.lul.interceptor.ExceptionInterceptor"></interceptor>
</interceptors> <global-results>
<result name="error">error.jsp</result>
</global-results> <global-exception-mappings>
<exception-mapping result="error" exception="com.lul.exception.BusinessException"></exception-mapping>
</global-exception-mappings> <action name="insert" class="com.lul.action.InsertAction">
<result name="success">success.jsp</result>
<interceptor-ref name="exceptionInceptor"></interceptor-ref>
</action> 自定义异常类:
Java代码
public class BusinessException extends RuntimeException {
private static final long serialVersionUID = 1L;
public BusinessException(String errorMessage) {
super(errorMessage);
}
}
自定义用于异常处理的拦截器:
public String intercept(ActionInvocation invocation) throws Exception {
String result = null;
try {
result = invocation.invoke();
} catch(DataAccessException dae) {
throw new BusinessException("数据库操作失败");
}
...
...捕获常见的异常,并以友好异常信息抛出
}
在调用insert.action后,dao抛出异常,但不知为什么不能跳到error.jsp页面,而是
HTTP Status 500 - -------------------------------------------------------------------------------- type Exception report message description The server encountered an internal error () that prevented it from fulfilling this request. exception javax.servlet.ServletException: com.lul.exception.BusinessException: Sorry, 数据库操作失败 Please try again!
org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:515)
org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:419) 有哪位高手知道错误原因,请指教! 书上讲的都是用系统默认的异常,自定义异常和拦截器,应该如何处理,现在不能跳到error.jsp错误处理页面!!!
<interceptors>
<interceptor name="exception" class="com.opensymphony.xwork.interceptor.ExceptionMappingInterceptor"></interceptor>
<interceptor name="exceptionInceptor" class="com.lul.interceptor.ExceptionInterceptor"></interceptor>
</interceptors> <global-results>
<result name="error">error.jsp</result>
</global-results> <global-exception-mappings>
<exception-mapping result="error" exception="com.lul.exception.BusinessException"></exception-mapping>
</global-exception-mappings> <action name="insert" class="com.lul.action.InsertAction">
<result name="success">success.jsp</result>
<interceptor-ref name="exceptionInceptor"></interceptor-ref>
</action> 自定义异常类:
Java代码
public class BusinessException extends RuntimeException {
private static final long serialVersionUID = 1L;
public BusinessException(String errorMessage) {
super(errorMessage);
}
}
自定义用于异常处理的拦截器:
public String intercept(ActionInvocation invocation) throws Exception {
String result = null;
try {
result = invocation.invoke();
} catch(DataAccessException dae) {
throw new BusinessException("数据库操作失败");
}
...
...捕获常见的异常,并以友好异常信息抛出
}
在调用insert.action后,dao抛出异常,但不知为什么不能跳到error.jsp页面,而是
HTTP Status 500 - -------------------------------------------------------------------------------- type Exception report message description The server encountered an internal error () that prevented it from fulfilling this request. exception javax.servlet.ServletException: com.lul.exception.BusinessException: Sorry, 数据库操作失败 Please try again!
org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:515)
org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:419) 有哪位高手知道错误原因,请指教! 书上讲的都是用系统默认的异常,自定义异常和拦截器,应该如何处理,现在不能跳到error.jsp错误处理页面!!!
<interceptors>
<interceptor name="exception" class="com.opensymphony.xwork.interceptor.ExceptionMappingInterceptor"> </interceptor>
<interceptor name="exceptionInceptor" class="com.lul.interceptor.ExceptionInterceptor"> </interceptor> <interceptor-stack name="mydefault">
<!-- defaultStack必须放在最前面 -->
<interceptor-ref name="defaultStack" />
<interceptor-ref name="exception" />
<interceptor-ref name="exceptionInceptor" />
</interceptor-stack>
</interceptors>
<default-interceptor-ref name="mydefault" />
<global-results>
<result name="error">error.jsp </result>
</global-results>