日期:2014-05-18  浏览次数:20878 次

用Filter处理异常失败,throw的异常根本传不到catch
我想用filter做处理异常的功能,遇到了点小麻烦
JSP页面主动throw一个Exception e=new Exception("1111");
最外层的filter触发catch(Exception e){XXX}  但是里面catch到的和我throw的完全不一样
说明:
1.弄了个Exception Filter处理异常,
而且它的filter是filter第一个   
filter mapping是filter mapping第一个
2.我一开始用了自定义异常类AccountException,曾经以为是多态没处理好,搞不清楚向上转类型和向下转类型,后来测试了各种多态的思想,还是不行。索性就让整个工程彻底和自定义异常类没关系了--如今throw catch的都是基本类Exception ,还是不行。
3.框架虽然是SSH整合的,但是SSH功能正常(顺便感谢前几天帮我的那几位),我觉得还是异常的对象没传过去。
4.经过我一步步调试,问题已经基本找到,原理不清楚,解决方案未知。

web.xml

<?xml version="1.0" encoding="GBK"?>
<web-app version="3.0" 
xmlns="http://java.sun.com/xml/ns/javaee" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
  <display-name></display-name>
  
 
   <context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/classes/applicationContext.xml</param-value>

</context-param>


<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<!-- 我的filter -->
<filter>
<filter-name>ExceptionFilter</filter-name>
<filter-class>filter.ExceptionFilter</filter-class>
<init-param>
<param-name>errorPage</param-name>
<param-value>/error.jsp</param-value>
</init-param>

</filter>
<filter>
<filter-name>OpenSessionInViewFilter</filter-name>
<filter-class>
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
<init-param>
<param-name>sessionFactoryBeanName</param-name>
<param-value>sessionFactory</param-value>
</init-param>

<init-param>
<param-name>singleSession</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>flushMode</param-name>
<param-value>AUTO</param-value>
</init-param>
</filter>

  <filter>
   <filter-name>struts2</filter-name>
   <filter-class>
   org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
   </filter-class>
  </filter>
  
  
  <filter-mapping>
<filter-name>ExceptionFilter</filter-name>
<url-pattern>/*</url-pattern>
<url-pattern>*.action</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher>
</filter-mapping>
  <filter-mapping>
<filter-name>OpenSessionInViewFilter</filter-name>
<url-pattern>*.action</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>