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.