Filter tag in web. xml and web. xmlfilter tag

Source: Internet
Author: User

Filter tag in web. xml and web. xmlfilter tag
Filter label description

Filter and filter-mapping appear in pairs:

<! -- Ing filter --> <filter-mapping> <filter-name> FilterDemo02 </filter-name> <! -- "/*" Indicates blocking all requests --> <url-pattern>/* </url-pattern> </filter-mapping>
 

The <filter-mapping> element is used to set the resources intercepted by a Filter. Resources intercepted by a Filter can be specified in two ways: Servlet name and Resource Access Request Path.

<Filter-name> the subelement is used to set the Registration name of the filter. The value must be the name of the filter declared in the <filter> element.

<Url-pattern> set the Request Path intercepted by the filter (the URL style associated with the filter)

<Servlet-name> specify the name of the Servlet intercepted by the filter.

<Dispatcher> specify the method in which the resource intercepted by the filter is called by the Servlet container. It can be one of REQUEST, INCLUDE, FORWARD, and ERROR. The default value is REQUEST. You can set multiple <dispatcher> sub-elements to specify filters to block multiple resource calling methods. As follows:

  <filter-mapping>    <filter-name>testFilter</filter-name>    <url-pattern>/index.jsp</url-pattern>    <dispatcher>REQUEST</dispatcher>    <dispatcher>FORWARD</dispatcher>  </filter-mapping>
 

<Dispatcher> values that can be set by sub-elements and their meanings:

REQUEST: When you directly access the page, the Web Container will call the filter. If the target resource is accessed through the include () or forward () method of RequestDispatcher, the filter will not be called.
INCLUDE: if the target resource is accessed through the include () method of RequestDispatcher, the filter will be called. In addition, the filter will not be called.
FORWARD: if the target resource is accessed through the forward () method of RequestDispatcher, the filter is called. In addition, the filter is not called.
ERROR: if the target resource is called through the declarative Exception Handling Mechanism, the filter will be called. In addition, the filter will not be called.

 

Related Article

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.