A Servlet filter is a piece of software that can intercept HTTP requests aimed at your website. The init() method of the servlet filter is called when it is loaded for the first time, much like servlets.
When a request/response pair is transmitted through the chain owing to a client request for a resource at the end of the chain, the container calls the Filter's doFilter method. This method's FilterChain parameter allows the Filter to forward the request and response to the next object in the chain.
As you can see, a filter can be mapped to one or more servlets, and several filters can be mapped to a servlet.
A servlet is a Java programming language class that is used to improve the capabilities of servers that host request-response programming model applications. Servlets can react to any form of request, but they are most typically used to extend web server-hosted applications.
Share a personalized message with your friends.