日期:2014-05-16  浏览次数:20396 次

Filter过滤器只过滤jsp文件不过滤action请求解决方案



解决办法:在web.xml中将filter的配置放在struts2配置的前面。如下例子:

<filter>
        <filter-name>validateFilter</filter-name>
        <filter-class>com.yunhao.system.filter.ValidateFilter</filter-class>
    </filter>
  <filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
        <init-param>
         <param-name>config</param-name>
         <param-value>struts-default.xml,struts-plugin.xml,struts.xml</param-value>
        </init-param>
    </filter>



<filter-mapping>
     <filter-name>validateFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

就这样就ok了。