Filter Chinese means filters . As the name implies , filters can act as a filter between the browser and the target resource . for example: water purifier can be seen as a filter in life, he can filter the impurities in the sewage , so that the incoming sewage into clean water .
For web applications , a filter is a Web component residing in a server that intercepts request and response information between a client and a Web resource.
WEB resources may include Servlets,jsps,HTML pages, etc.
To create a new filter file
The configuration of the Web. xml file, the configuration of the filter, and the configuration of the servlet are similar, but the <url-pattern> of the filter, the following is the exact intercept: Specify a specific intercept path, or *.jsp: Block all JSP files or/web/* : Intercepts all files under the Web file.
In the Dofilter, Chain.dofilter is the meaning of release.
When there are multiple filter filters, the sequence of filtering execution is determined before and after the configuration of <url-pattern> in Web. Xml.
Filter 's life cycle is similar to Servlet
Constructor : Creating A filter instance is called , and the filter instance Server is created once it is started
Init (): The instance is called immediately after it is created to perform some initialization operations on the Filter
DoFilter (): The primary method of filter, which is used to complete the main function of the filters, is called every time the target resource is accessed.
Destroy (): called when the server is stopped to release resources.
The principle and configuration of the filter filter for Java Filters _ Learning Notes