多个Filter 的执行顺序

来源:互联网 发布:数组和指针的区别 编辑:程序博客网 时间:2024/04/30 11:02
如果在WEB.XML中有多个Filter,则执行顺序为

<filter-mapping>的顺序

 

<filter-mapping>

<filter-name>secondFilter</filter-name>

<url-pattern>/*</url-pattern>

</filter-mapping>

<filter-mapping>

<filter-name>sysoutFilter</filter-name>

<url-pattern>/*</url-pattern>

</filter-mapping>

 

执行顺序为 secondFilter, sysoutFilter

 

Configuring a Chain of Filters

WebLogic Server creates a chain of filters by creating a list of all the filter mappings that match an incoming HTTP request. The ordering of the list is determined by the following sequence:

  1. Filters where the filter-mapping element contains a url-pattern that matches the request are added to the chain in the order they appear in theweb.xml deployment descriptor.
  2. Filters where the filter-mapping element contains a servlet-name that matches the request are added to the chainafter the filters that match a URL pattern.
  3. The last item in the chain is always the originally requested resource.

In your filter class, use the FilterChain.doFilter() method to invoke the next item in the chain.