Java Filter的执行顺序
来源:互联网 发布:js取得select选中的值 编辑:程序博客网 时间:2024/05/18 01:09
IMPORTANT: The Container’s rules for ordering filters:1) ALL filters with matching URL patterns are located first. This is NOT the same as the URL mapping rules the Container uses to choose the “winner” when a client makes a request for a resource, because ALL filters that match will be placed in the chain!! Filters with matching URL patterns are placed in the chain in the order in which they are declared in the DD.<filter-name>BeerRequest1</filter-name><url-pattern>*.do</url-pattern></filter-mapping><filter-name>BeerRequest2</filter-name><servlet-name>AdviceServlet</servlet-name></filter-mapping>Write down the sequence in which the filters will be executed for each request path. Assume Filter1 - Filter5 have been properly declared.
When more than one filter is mapped to a given resource, the Container uses the following rules:
2) Once all filters with matching URLs are placed in the chain, the Container does the same thing with filters that have a matching <servlet-name> in the DD.
说白了就两条:
1)先执行带有url-pattern标签的filter,再执行带有servlet-name标签的filter。两种标签的书写方式如下:
<filter-mapping>
<filter-name>BeerRequest1</filter-name>
<url-pattern>*.do</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>BeerRequest2</filter-name>
<servlet-name>AdviceServlet</servlet-name>
</filter-mapping>
前者优先执行。
2)如果同为url-pattern或servlet-name,则会按照在web.xml中的声明顺序执行。
下面举个例子:
<filter-mapping><filter-name>Filter1</filter-name><url-pattern>/Recipes/*</url-pattern></filter-mapping><filter-mapping><filter-name>Filter2</filter-name><servlet-name>/Recipes/HopsList.do</servlet-name></filter-mapping><filter-mapping><filter-name>Filter3</filter-name><url-pattern>/Recipes/Add/*</url-pattern></filter-mapping><filter-mapping><filter-name>Filter4</filter-name><servlet-name>/Recipes/Modify/ModRecipes.do</servlet-name></filter-mapping><filter-mapping><filter-name>Filter5</filter-name><url-pattern>/*</url-pattern></filter-mapping>
Request path Filter Sequence
/Recipes/HopsReport.do 1, 5
/Recipes/HopsList.do 1, 5, 2
/Recipes/Modify/ModRecipes.do 1, 5, 4
/HopsList.do 5
/Recipes/Add/AddRecipes.do 1, 3, 5
- Java Filter的执行顺序
- FILTER的执行顺序
- filter的执行顺序
- JavaWeb Filter 的执行顺序
- Filter过滤器执行的顺序
- Servlet 中 Filter的执行顺序
- 多个Filter 的执行顺序
- Filter 过滤器的执行顺序与实例
- 多个Filter的执行顺序
- 基于注解方式的Filter执行顺序
- 多个Filter 的执行顺序
- [转]filter、servlet、interceptor的执行顺序
- Filter、Servlet和Interceptor的执行顺序
- Filter 执行顺序介绍
- Filter(五)FilterChain执行顺序
- filter执行顺序与实例
- Filter介绍,执行顺序,实例
- 探究Servlet Filter 执行顺序
- java Socket通信实例
- git reflog
- c 语言学习笔记十二
- html模仿苹果电脑任务栏菜单
- Android界面View及ViewGroup
- Java Filter的执行顺序
- 调整IIS 7并发请求数
- 邂逅在华灯初上
- android窗体加载过程剖析之事件的分发机制
- linux at命令使用案例
- 关于HttpUtility.UrlEncode,HttpUtility.UrlDecode,Server.UrlEncode,Server.UrlDecode
- Mysql索引优化实例讲解
- 父子进程对相同存贮区域访问
- 颜色与眼睛