设为首页 加入收藏

TOP

Java Filter的执行顺序
2014-11-24 07:34:53 来源: 作者: 【 】 浏览:0
Tags:Java Filter 执行 顺序

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.BeerRequest1*.doBeerRequest2AdviceServletWrite 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 in the DD.


说白了就两条:


1)先执行带有url-pattern标签的filter,再执行带有servlet-name标签的filter。两种标签的书写方式如下:



BeerRequest1
*.do

BeerRequest2
AdviceServlet


前者优先执行。


2)如果同为url-pattern或servlet-name,则会按照在web.xml中的声明顺序执行。


下面举个例子:



Filter1
/Recipes/*


Filter2
/Recipes/HopsList.do


Filter3
/Recipes/Add/*


Filter4
/Recipes/Modify/ModRecipes.do


Filter5
/*


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


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Android之高仿飞鸽传书热点创建与.. 下一篇C++ 虚函数与纯虚函数

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·Redis 分布式锁全解 (2025-12-25 17:19:51)
·SpringBoot 整合 Red (2025-12-25 17:19:48)
·MongoDB 索引 - 菜鸟 (2025-12-25 17:19:45)
·What Is Linux (2025-12-25 16:57:17)
·Linux小白必备:超全 (2025-12-25 16:57:14)