Relationship between Spring DispatcherServlet and Filters

血红的双手。 提交于 2020-06-12 09:14:00

问题


Spring MVC uses a DispatcherServlet to route control to an appropriate Controller. But where do filters fit into the flow? If I specify a filter to perform session management or authentication, will the filters always be called before DispatcherServlet?

My confusion comes from the fact that they both specify a URL pattern. What happens if they both provide the same url pattern?


回答1:


This is not really specific to Spring and Spring MVC. In general fitlers are always called before servlets. When you have several filters and one servlet matching given URL pattern, all filters are executed first in the order of <filter-mapping> definitions and the servlet is executed last.

This way you can modify the request on the fly or even ignore the servlet altogether.



来源:https://stackoverflow.com/questions/11342010/relationship-between-spring-dispatcherservlet-and-filters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!