Pr.Pg Next Pg

How the Servlet Container Invokes Filters tutorials

  • Below image shows how the servlet container invokes filters. On the left is a scenario where no filters are configured for the servlet being called. On the right, several filters (1, 2, , N) have been configured in a chain to be invoked by the container before the servlet is called. Specify in the web.xml file which servlets cause the container to invoke the filters.

Invoking Filters

Servlet Invocation with and without filters

 

  • Note: filters are not Note: filters are not servlets. They do not implement and override HttpServlet methods such as doGet() or doPost(). Rather, a filter implements the methods of thejavax.servlet.Filter interface. The methods are below with description:

 

S.N.

Method

Description

1

public void doFilter (ServletRequest, ServletResponse, FilterChain)

This method is called by the container each time a request/response pair is passed through the chain due to a client request for a resource at the end of the chain.

2

public void init(FilterConfig filterConfig)

This method is called by the web container to indicate to a filter that it is being placed into service.

3

public void destroy()

This method is called by the web container to indicate to a filter that it is being taken out of service.

Pr.Pg border                                              Next Pg