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> 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>