<filter-mapping>--<dispatcher>

Source: Internet
Author: User

The 2.4 version of the servlet specification adds a new <dispatcher> element to the subordinate descriptor, which has four possible values: Request,forward,include and error, which can be found in a < Add any number of <dispatcher&gt to the filter-mapping> element, so that the filter will act on the request that comes directly from the client, through the request of forward. Request via include and request via <error-page>. If no < Dispatcher > element is specified, the default value is request. There are a few examples to help you understand.
Example 1:
<filter-mapping>
<filter-name>logging filter</filter-name>
<url-pattern>/products/*</url-pattern>
</filter-mapping>
In this case, the filter will function directly from the client to/products/... The request started. Because there is no < dispatcher > element, the default value is request.

Example 2:
<filter-mapping>
<filter-name>logging filter</filter-name>
<servlet-name>ProductServlet</servlet-name>
<dispatcher>INCLUDE</dispatcher>
</filter-mapping>
In this case, if the request is passed to the Productservlet request through the include method of request dispatcher, it is filtered by this filter. Other requests, such as those that come directly from the client, are not required to pass through the filter productservlet.
There are two ways to specify how filter is matched: directly specify Url-pattern and the specified servlet, which is equivalent to the url-pattern of the specified servlet as the filter's matching pattern
The path match for filter is the same as the servlet and follows the instructions in the srv.11.2 specification of Mappings section of the servlet specification

Example 3:
<filter-mapping>
<filter-name>logging filter</filter-name>
<url-pattern>/products/*</url-pattern>
<dispatcher>FORWARD</dispatcher>
<dispatcher>REQUEST</dispatcher>
</filter-mapping>
In this case, if the request is in/products/... and is passed through the forward method of the request dispatcher or directly from the client, it must pass through this filter.
The dispatcher has four legal values: forward, request, include,and  ERROR. A value of FORWARD means the Filter will be  Appliedunder requestdispatcher.forward ()  calls. a value of requestmeans the  filter will be applied under ordinary client calls to the  path or servlet. A value of INCLUDE means the Filter  Will be applied under requestdispatcher.include ()  calls. a value of  error means the filter will be applied under the error  page mechanism. the absence of any dispatcher elements in a  filter-mapping indicates a default of applying filters only  Under ordinary client calls to the path or servlet.

<filter-mapping>--<dispatcher>

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.