The servlet filter uses

Source: Internet
Author: User

The servlet filter is sandwiched between the user and the servlet, and can intercept and preprocess or interrupt {user-to-servlet requests or servlet-to-user responses}, but cannot handle and respond to user requests by itself.

The filter class must implement the three methods of the filter interface:

Init: Create an instance of each filter based on the configuration in Web. xml

DoFilter: Executed when the user requests the corresponding filtered URL

Destroy:web container unloading filter is performed

For the same request, you can have as many filter as the filter chain (chain) in the order defined by the filter in Web. Xml.

The first declaration in Web. XML is first executed doFilter, there is a chain.dofilter (request, response) in DoFilter, and the DoFilter method of the next filter in the filter chain continues. The DoFilter method is roughly as follows: the pre-processing block ====chain.dofilter (request, response); ===== post-processing. Therefore, after the declaration of the Dofilter method will be done first.

    <Filter>        <Filter-name>Encodingfilter</Filter-name>        <Filter-class>Org.springframework.web.filter.CharacterEncodingFilter</Filter-class>        <Init-param>            <Param-name>Encoding</Param-name>            <Param-value>UTF-8</Param-value>        </Init-param>        <Init-param>            <Param-name>Forceencoding</Param-name>            <Param-value>True</Param-value>        </Init-param>    </Filter>    <filter-mapping>        <Filter-name>Encodingfilter</Filter-name>        <Url-pattern>/*</Url-pattern>    </filter-mapping>

The filter defined in Web. XML can execute the init parameter by setting the filter Init-param. Filter-mapping set the URL address for this filter

The servlet filter uses

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.