zoukankan      html  css  js  c++  java
  • Filter学习:项目第八阶段

     
    public interface Filter
    A filter is an object that performs filtering tasks on either the request to a resource (a servlet or static content), or on the response from a resource, or both.
    (过滤器是一个对象,它对资源(servlet或静态内容)的请求执行过滤任务,或对资源的响应,或两者都执行过滤任务。)
     
    Filters perform filtering in the doFilter method. Every Filter has access to a FilterConfig object from which it can obtain its initialization parameters, and a reference to the ServletContext which it can use, for example, to load resources needed for filtering tasks.
    (滤波器采用doFilter方法 执行过滤。每个过滤器访问FilterConfig 对象获得它的初始化参数,并参考ServletContext它可以使用,例如,加载过滤任务所需要的资源。)
     
    Filters are configured in the deployment descriptor of a web application.
    (过滤器配置在Web应用程序的部署描述符中。)

    Examples that have been identified for this design are:

    1. Authentication Filters           ----身份认证过滤
    2. Logging and Auditing Filters  ---日志和认证过滤
    3. Image conversion Filters  ----图像转换过滤器
    4. Data compression Filters  --数据压缩过滤器
    5. Encryption Filters   ---加密过滤
    6. Tokenizing Filters   
    7. Filters that trigger resource access events----触发资源访问事件的过滤器
    8. XSL/T filters
    9. Mime-type chain Filter         MIME型链过滤器
     
    Filter生命周期:
    先执行Filter的构造方法   
    然后执行Filterinit方法     init(FilterConfig filterConfig)
    执行FilterdoFilter方法,每次访问资源,只要匹配过滤的地址,就会调用。  doFilter()
    执行Filterdestroy方法   void destroy()
     
    FilterConfig
    FilterConfig类,一般有三个作用:
    1. 获取Filterweb.xml文件中配置的名称     ----filterConfig.getFilterName()
       
    2. 获取Filterweb.xml文件中配置的初始化参数  ---filterConfig.getFilterParameter("username")
       
    3. 通过FilterConfig类获取ServletContext对象实例  ---filterConfig.getServletContext();
    FilterChain 过滤器链(重点****)
    void doFilter(ServletRequest request,
                ServletResponse response,
                FilterChain chain)
                  throws IOException,
    
     
    Filter的拦截路径
    精确匹配 比如: /xxx/xxx/xxx.jsp /xxx/xxx/xxx.html
    目录匹配 比如:
    /abc/* 表示可以拦截abc目录下的所有资源,甚至是abc目录下的其他目录,
    /* 表示访问 当前工程下所有资源
    后缀名匹配 比如:*.jsp 表示拦截所有后缀为jsp文件资源
  • 相关阅读:
    自从学会了搭建开源网站,妈妈再也不担心我找不到web自动化学习环境啦!
    领导要我6点下班前创建1000个有效的手机号,现在5点半了!教你用random模块10分钟搞定!
    python:字符串 扩展分片:第三个限制值
    python字符串:索引和分片
    测试基础:测试用例设计策略
    测试基础:软件测试思维方式
    面试整理:python列表面试习题
    面试整理:linux
    测试的一些思考
    python ConfigParse模块中的方法
  • 原文地址:https://www.cnblogs.com/limingxian537423/p/7126794.html
Copyright © 2011-2022 走看看