Spring Framework — Filter vs Dispatcher Servlet vs Interceptor vs Controller

--

Hello everyone. In this article, we are going to look at Filter, Dispatcher Servlet, Interceptor, and Controller in the Spring framework. Understanding these components is a bit difficult initially for most Java developers as they sound similar. Each of these components has a specific purpose and knowing them well allows a developer to use them correctly. I have simplified the concepts with diagrams and examples.

Image Source: https://i.stack.imgur.com/9iCub.png

Before reading this, please go through my article about Servlets to have a deep understanding of Servlets and its terminologies

What is a Filter?

Image Source: https://media-exp1.licdn.com/dms/image/C4E12AQHtoFH1V88ZBA/article-cover_image-shrink_600_2000/0/1638174025806?e=1666828800&v=beta&t=-PLrfrtXAfFqToQ297jZ4Ux6ELemI-qzi9hYYzMVe0c

As seen in the diagram above, Filters are part of the Servlet Container of the web server. It does not belong to any framework like Struts or Spring. Filters are used to manipulate the requests and the requests can even be blocked before it reaches the Servlet. It can also…

--

--

Dineshchandgr - A Top writer in Technology
Javarevisited

Principal Software Engineer and Technical Lead focussed on Backend Engineering who likes to upgrade the tech skills and share knowledge to the community