Servlet 中 Filter的執行順序

ServletFilter 中 doFilter()方法將調用過濾鏈中的下一個過濾方法,當下一個方法完成後,控制權將重新回到調用改方法的上級過濾器中。類似於 遞歸調用

 

 

 

 

 










另外,如果過濾器的doFilter()方法中 寫出了定製的響應後,方法無需連到其它過濾器就能返回。這就是過濾器阻止後續處理的方法。

 

 

public void doFilter( ServletRequest req, 

ServletResponse res, FilterChain chain) 

throws IOException, ServletException {

PrintWriter out = res.getWriter();

out.write("Access Denied");

out.flush();

out.close();

}

以上爲有FilterChain chain和無FilterChain chain的區別,當無chain.doFilter(req, res);時下個一個filter就不會被調用。

 

 

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章