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.