Servlet中filter的执行顺序以及urlPatterns和servletNames之间的关系
来源:互联网 发布:mac怎么设置iphone铃声 编辑:程序博客网 时间:2024/05/16 00:42
servlet3.0以前
用web.xml中的<filter-mapping>顺序决定filter的执行顺序
<span style="white-space:pre"></span><filter><filter-name>firstfilter</filter-name><filter-class>filter.FirstFilter</filter-class></filter><filter><filter-name>secondfilter</filter-name><filter-class>filter.SecondFilter</filter-class></filter><filter-mapping><filter-name>firstfilter</filter-name><url-pattern>/*</url-pattern></filter-mapping><filter-mapping><filter-name>secondfilter</filter-name><url-pattern>/*</url-pattern></filter-mapping>
执行结果
servlet3.0以后
通过注解配置filter时,没有专门的指令来配置filter执行的先后。确定filter执行的先后是根据filter类名的字母表顺序
声明filter
@WebFilter(filterName = "second", urlPatterns = { "/*" })public class SecondFilter implements Filter {}@WebFilter(filterName = "first", urlPatterns = { "/*" })public class FirstFilter implements Filter {}执行结果
@WebFilter(filterName = "second", urlPatterns = { "/*" })public class SecondFilter implements Filter {}@WebFilter(filterName = "first", urlPatterns = { "/*" })public class ZFirstFilter implements Filter {}
执行结果
可以在web.xml中单独写入<filter-mapping>配置filter顺序。
<span style="white-space:pre"></span><filter-mapping><filter-name>firstfilter</filter-name></filter-mapping><filter-mapping><filter-name>secondfilter</filter-name></filter-mapping>
另urlPatterns和servletNames之间的关系
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:
- Filters where the
filter-mapping
element contains aurl-pattern
that matches the request are added to the chain in the order they appear in theweb.xml
deployment descriptor. - Filters where the
filter-mapping
element contains aservlet-name
that matches the request are added to the chain after the filters that match a URL pattern. - 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.
0 0
- Servlet中filter的执行顺序以及urlPatterns和servletNames之间的关系
- Servlet 中 Filter的执行顺序
- Filter、Servlet和Interceptor的执行顺序
- Tomcat的valve、filter和servlet的执行顺序
- Filter和Servlet的执行顺序与实例
- ServletContext,Listener,Filter和自启动Servlet的执行顺序
- servlet 和filter区别和servlet、filter、interceptor的执行顺序
- [转]servlet 和filter区别和servlet、filter、interceptor的执行顺序
- servlet 和filter区别和servlet、filter、interceptor的执行顺序
- Servlet,filter, struts,jsp之间的关系
- [转]filter、servlet、interceptor的执行顺序
- servlet 和 filter执行顺序
- jsp 中request 、response以及filter互相之间的关系
- 容器执行Servlet API 中ServletContext、ServletContextListener、Filter、Servlet的顺序
- servlet理解和Spring的DispatcherServlet理解以及之间关系
- Java中Filter、Listener的学习以及istener、 filter、servlet 加载顺序详解
- Linux中profile、bashrc、~/.bash_profile、~/.bashrc、~/.bash_profile之间的区别和联系以及执行顺序
- Linux中profile、bashrc、~/.bash_profile、~/.bashrc、~/.bash_profile之间的区别和联系以及执行顺序
- 开放API接口 笑话、天气、新闻
- 第六周项目一深复制体验
- CentOS6.5添加SFTP上传的用户的步骤
- BZOJ3210【曼哈顿距离】
- Android ViewGroup触摸事件拦截详解
- Servlet中filter的执行顺序以及urlPatterns和servletNames之间的关系
- 提高PHP编程效率的53个要点(转)
- 同步、异步、阻塞、非阻塞
- 正则表达式
- ARM定义特殊寄存器(*(volatile unsigned long *))的理解
- 如何做好乙方
- UiAutomator自动化测试使用小结(一)
- xcode中ineligible devices的注意事项
- android 学习笔记代码片段(5)