Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Relationship between Spring DispatcherServlet and Filters

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?

like image 780
Jack Avatar asked Dec 10 '25 09:12

Jack


1 Answers

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.

like image 147
Tomasz Nurkiewicz Avatar answered Dec 13 '25 03:12

Tomasz Nurkiewicz