zoukankan      html  css  js  c++  java
  • Spring MVC过滤器-委派过滤器代理(DelegatingFilterProxy)

    org.springframework.web.filter中有一个特殊的类——DelegatingFilterProxy,该类其实并不能说是一个过滤器,它的原型是FilterToBeanProxy,即将Filter作为spring的bean,由spring来管理。

            配置DelegatingFilterProxy的常用方法如下所示:

    <filter>
    		<filter-name>testFilter</filter-name>
    		<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    		<init-param>
    			<param-name>targetBeanName</param-name>
    			<param-value>testBean</param-value>
    		</init-param>
    	</filter>        
            <filter-mapping>
    		<filter-name>testFilter</filter-name>
    		<url-pattern>/*</url-pattern>
    	</filter-mapping>
    

      

            含义是有一个过滤器,它指向一个bean,这个bean在spring中的名字为testBean,testBean也必需实现javax.servlet.Filter。

            其他可以通过web.xml传递的参数如下:

            (1) contextAttribute,使用委派Bean的范围,其值必须从org.springframework.context.ApplicationContext.WebApplicationContext中取得,默认值是session;

            (2) targetFilterLifecycle,是否调用Filter的init和destroy方法,默认为false。

            所以DelegationgFilterProxy的全项配置信息如下:

    <filter>
    		<filter-name>testFilter</filter-name>
    		<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    		<init-param>
    			<param-name>targetBeanName</param-name>
    			<param-value>testBean</param-value>
    		</init-param>
                    <init-param>
    			<param-name>contextAttribute</param-name>
    			<param-value>session</param-value>
    		</init-param>
                    <init-param>
    			<param-name>targetFilterLifecycle</param-name>
    			<param-value>false</param-value>
    		</init-param>
    	</filter>        
            <filter-mapping>
    		<filter-name>testFilter</filter-name>
    		<url-pattern>/*</url-pattern>
    	</filter-mapping>
    

      

     

      

  • 相关阅读:
    Windows 下安装 Python环境安装
    关于form表单提交ajaxForm和ajaxSubmit的用法与区别
    .NET Core Runtime 和 .NET Core SDK
    路由表中没有与提供的值匹配的路由
    SQL server Cannot find one or more
    CentOS7安装完毕,重新开机启动后显示: Initial setup of CentOS Linux 7 (core)
    private static
    接口和抽象类
    static const readonly
    frameset的使用小结
  • 原文地址:https://www.cnblogs.com/JAYIT/p/6014837.html
Copyright © 2011-2022 走看看