the role of Web.xml in the __web

Source: Internet
Author: User

In the 2.4 version of the servlet specification, a new <dispatcher> element is added to the subordinate descriptor, which has four possible values: Request,forward,include and error, which can be used in a < Add any number of <dispatcher> to the filter-mapping> element, so that filter will function directly from the client request, through the forward over the request, Request via include and request through <error-page>. If no <dispatcher> element is specified, the default value is request. The following are some examples to help you understand.
Example 1:

<filter-mapping>   
  <filter-name>logging   filter</filter-name>   
  <url-pattern>/ Products/*</url-pattern>   


In this case, the filter will be sent directly from the client to/products/... The start request. Because there are no <dispatcher> elements in place, the default is request.

  <filter-mapping>   
      <filter-name>logging   filter</filter-name>   
      <servlet-name> Productservlet</servlet-name>   
      <dispatcher>INCLUDE</dispatcher>   
  

In this case, the request is filtered through this filter if it is a request to Productservlet passed through the include method of the request dispatcher. Other requests for productservlet, such as those coming directly from the client, do not need to pass through this filter.
There are two ways to specify how the filter is matched: specifying the Url-pattern and specifying a servlet directly, which corresponds to the url-pattern of the specified servlet as the matching pattern of the filter. Filter path matching is the same as servlet, and follows the instructions in the srv.11.2 specification of Mappings section of the servlet specification.

  <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 based on/products/... The beginning and passing through the forward method of request dispatcher or directly from the client, you must pass through this 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.