javaWeb自己定义可排序过滤器注解,解决Servlet3.0下@WebFilter注解无法排序问题

com.lwl.anno

凝视类型 @WebFilterSort


须要用的jar包 http://download.csdn.net/detail/u013202238/9431110


用该注解注冊的Filter默认在部署描写叙述符中的过滤器载入后载入,能够使用isMatchAfter更改载入顺序
为Filter排序注解,排序从1開始,1优先级最高
以url-pattern 过滤的最先运行,以servlet-name 过滤的在所有url-pattern运行后运行
在web.xml中设置參数
< context-param>
        < description>被扫描的过滤器的所在包< /description>
                < param-name>filterPackage< /param-name>
                < param-value>com.test.filter.pack< /param-value>
         < /context-param>
filterPackage  必填,包范围越小越好
filterInitScanJar 选填
                  是否扫描jar包中的类,默觉得false不扫描,假设不打印能够不配置该參数
filterInitDebug 选填
                     是否打印过滤器初始化信息(按排序顺序),默认false不打印,假设不打印能够不配置该參数

    • 必需元素概要

      所需元素 
      限定符和类型 必需的元素和说明
      int value
      排序优先级
    • 可选元素概要

      可选元素 
      限定符和类型 可选元素和说明
      boolean asyncSupported
      Declares whether the filter supports asynchronous operation mode.
      DispatcherType[] dispatcherTypes
      The dispatcher types to which the filter applies
      default {DispatcherType.REQUEST};
      java.lang.String displayName
      The display name of the filter,default ""
      java.lang.String filterName
      The name of the filter,default ""
      boolean isMatchAfter
      表示该过滤器相对于部署描写叙述符中过滤器的顺序 
      假设使用的參数为false,那么该过滤器映射将在部署描写叙述符中描写叙述的全部过滤器载入前进行载入, 
      假设为true( 默认 ),那么部署描写叙述符中的过滤器将先被载入
      java.lang.String[] servletNames
      The names of the servlets to which the filter applies.
      java.lang.String[] urlPatterns
      The URL patterns to which the filter applies,default {"/*"}
    • 元素具体资料

      • value

        public abstract int value
        排序优先级
      • isMatchAfter

        public abstract boolean isMatchAfter
        表示该过滤器相对于部署描写叙述符中过滤器的顺序 
        假设使用的參数为false,那么该过滤器映射将在部署描写叙述符中描写叙述的全部过滤器载入前进行载入, 
        假设为true( 默认 ),那么部署描写叙述符中的过滤器将先被载入
        默认值:
        true
      • displayName

        public abstract java.lang.String displayName
        The display name of the filter,default ""
        默认值:
        ""
      • filterName

        public abstract java.lang.String filterName
        The name of the filter,default ""
        默认值:
        ""
      • servletNames

        public abstract java.lang.String[] servletNames
        The names of the servlets to which the filter applies.,default {}
        默认值:
        {}
      • urlPatterns

        public abstract java.lang.String[] urlPatterns
        The URL patterns to which the filter applies,default {"/*"}
        默认值:
        "/*"
      • dispatcherTypes

        public abstract DispatcherType[] dispatcherTypes
        The dispatcher types to which the filter applies
        default {DispatcherType.REQUEST};
        默认值:
        <error>
      • asyncSupported

        public abstract boolean asyncSupported
        Declares whether the filter supports asynchronous operation mode.
        default  false
        另请參阅:
        javax.servlet.ServletRequest#startAsyncjavax.servlet.ServletRequest#startAsync(ServletRequest, ServletResponse)
        默认值:
        false
原文地址:https://www.cnblogs.com/yfceshi/p/7008234.html