此類實現了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,下一個過濾器將不會被執行。