DelegatingFilterProxy就是一个对于servlet filter的代理,用这个类的好处主要是通过spring容器来管理servlet filter的生命周期,还有就是如果filter中需要一些Spring容器的实例,可以通过spring直接注入,另外读取一些配置文件这些便利的操作都可以通过Spring来配置实现。
在web.xml中配置如下:
(1)配置方法一:
<!-- 在使用DelegatingFilterProxy代理filter的时候必须加上如下俩个web配置,否则报错 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- 设置过滤器 -->
<filter>
<filter-name>LoginFilter</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>LoginFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
(2)配置方法二:
<!-- 在使用DelegatingFilterProxy代理filter的时候必须加上如下俩个web配置,否则