The principle and configuration of the filter filter for Java Filters _ Learning Notes

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.