How Tomcat works之第十一章之ApplicationFilterChain

来源:互联网 发布:智慧树网络课程答案doc 编辑:程序博客网 时间:2024/05/17 06:05

此类实现了javax.servlet.FilterChain接口.StandardWrapperValue类的invoke方法创建了这个类的实例并调用了它的doFilter方法.ApplicationFilterChain类的doFilter方法调用了这个链中的第一个过滤器的doFilter方法。Filter接口的doFilter方法有如下标签:

 

public voiddoFilter(ServletRaquest request, ServletResponse response, FilterChain chain)throws java.io.IOException, ServletException

 

 

ApplicationFilterChain的doFilter方法的第三个参数就是其自身实例,传递给filter的doFilter方法。

 

从它的doFilter方法中,通过调用FilterChain对象的doFilter方法,一个过滤器可以调用另一个过滤器。下面是一个filter中doFilter方法实现的例子。

 

public voiddoFilter(ServletRequest request, ServletResponse response, FilterChain chain)throws IOException, ServletException { // do something here ...chain.doFilter(request, response); }

 

就如你所看见的,doFilter方法的最后一行调用了FilterChain的doFIlter方法。如果filter是过滤器链中的最后一个一个filter,将调用请求servlet的service方法。如果没有调用chain.doFilter,下一个过滤器将不会被执行。

0 0
原创粉丝点击