Summary of the Filter component

Source: Internet
Author: User

1. The role is to "pre-process and end" the requested resources. (The requested resource can be any url, including JSP, Servlet, and other filters ).

2. class definition method structure, with Code omitted ):

Class MyFilter implements Filter {init () {}// initialize doFilter () {// preprocessing // The requested resource after execution // The End of the requested resource after execution} destroy () {}// destruction}

3. instantiation:

By Tomcat at project startup new, object at startup), and only instantiate once, that is, a project only has one class object.

4. configuration method:

<Filter> <filter-name> name </filter-name> <filter-class> class path </filter-class> </filter> <filter-mapping> <filter- name> name </filter-name> <url-parttern> resource to be accessed <url-parttern> </filter-mapping>

5. method call:

Tomcat automatically calls the request once each time before the requested resource is accessed.

6. Applications in the production environment:

1) text encoding converter (request. setCharacterEncoding ("GBK "))

2) Permission controller (session. getAttribute ("user "))

3) text content filter.

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.