The life cycle of a filter typically passes through the following three stages:
Initialization
The init () method is called when the container loads the filter for the first time. The class contains a reference to the Filter Config object in this method. Our filters do not actually need to do this because the initialization information is not used, and this is only for demonstration purposes.
Filter:
Most of the time the filter is consumed here. The Dofilter method is called by the container, passing in a reference to the servlet request, Servlet Response, and Filter Chain objects that are pointed to in the requests/response chain respectively. The filter then has the opportunity to process the request, pass the processing task to the next resource in the chain (by calling the Dofilter method on the Filter Chain object reference), and then handle the response when processing control returns the filter.
Destruction:
The container immediately calls the Destroy () method before garbage collection, so that any necessary cleanup code can be executed.
About Chain.dofilter (request,response)
His role is to forward the request to the next object on the filter chain. The next one here is the next filter, if there is no filter that is the resource you requested. General filter is a chain, Web. XML is configured with several. and one by one.
Request resource, Filter2->filter3---Filter1
The meaning of filter chain.dofilter (request,response)