spring:過濾器和攔截器


過濾器:網絡通信模型的會話層控制;

攔截器:事務處理的aop注入(生命周期監控)。

 

Servlet Filter與HandlerInterceptor的對比

 

對於Servlet Filter,官方文檔中說的很好, 並且給出了常見的應用場景。

A filter is an object that performs filtering tasks on either the request to a resource (a servlet or static content), or on the response from a resource, or both. Filters perform filtering in the doFilter method. Every Filter has access to a FilterConfig object from which it can obtain its initialization parameters, and a reference to the ServletContext which it can use, for example, to load resources needed for filtering tasks.

Filters are configured in the deployment descriptor of a web application.

Examples that have been identified for this design are:

  • Authentication Filters
  • Logging and Auditing Filters
  • Image conversion Filters
  • Data compression Filters
  • Encryption Filters
  • Tokenizing Filters
  • Filters that trigger resource access events
  • XSL/T filters
  • Mime-type chain Filter

 

過濾器和攔截器的執行順序

 https://www.bbsmax.com/A/QW5Y046GJm/

 

https://my.oschina.net/zdtdtel/blog/3025880

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM