First filter
@Override
public void DoFilter (ServletRequest request, servletresponse response,
Filterchain chain) throws IOException, Servletexception {
Boolean B1 = false;
if (B1 = True) {
To continue this request, if there are multiple filters, go to the next filter
Chain.dofilter (request, response);
} else {
Redirect this request
((httpservletresponse) response). Sendredirect ("/xxxx");
}
System.out.println ("urlfilter_1 doFilter ...");
}
-----------------------------------------------------------------------------------
A second filter
@Override
public void DoFilter (ServletRequest request, servletresponse response,
Filterchain chain) throws IOException, Servletexception {
Boolean B2 = false;
if (B2 = True) {
To continue this request, if there are multiple filters, go to the next filter
Chain.dofilter (request, response);
} else {
Redirect this request
((httpservletresponse) response). Sendredirect ("/xxxx");
}
System.out.println ("urlfilter_1 doFilter ...");
}
-----------------------------------------------------------------------------------
A third filter
@Override
public void DoFilter (ServletRequest request, servletresponse response,
Filterchain chain) throws IOException, Servletexception {
Boolean B3 = false;
if (B3 = True) {
To continue this request, if there are multiple filters, go to the next filter
Chain.dofilter (request, response);
} else {
Redirect this request
((httpservletresponse) response). Sendredirect ("/xxxx");
}
System.out.println ("urlfilter_1 doFilter ...");
}
--------------------------------------------------------------------------------------------
The Web,xml is configured as follows
<filter>
<filter-name>url_1</filter-name>
<filter-class>com.boya.filters.UrlFilter_1</filter-class>
</filter>
<filter>
<filter-name>url_3</filter-name>
<filter-class>com.boya.filters.UrlFilter_3</filter-class>
</filter>
<filter>
<filter-name>url_2</filter-name>
<filter-class>com.boya.filters.UrlFilter_2</filter-class>
</filter>
<filter-mapping>
<filter-name>url_3</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>url_1</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>url_2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
--------------------------------------------------------------------------------------
Execution results are
Urlfilter_1 initialization ...
Urlfilter_3 initialization ...
Urlfilter_2 initialization ...
2013-9-29 13:38:40 Org.apache.coyote.AbstractProtocol Start
Info: Starting Protocolhandler ["http-bio-8080"]
2013-9-29 13:38:40 Org.apache.coyote.AbstractProtocol Start
Info: Starting Protocolhandler ["ajp-bio-8009"]
2013-9-29 13:38:40 Org.apache.catalina.startup.Catalina Start
Info: Server Startup in 596 ms
Urlfilter_2 DoFilter ...
Urlfilter_1 DoFilter ...
Urlfilter_3 DoFilter ...
-------------------------------------------------------------------------------------
Analysis results:
1.
Chain.dofilter (request, response);
In order to continue this request, if there is the next filter in the next filter, do not jump directly to the requested link.
2.
The order in which the filters are executed and the XML
<filter-mapping>
<filter-name>xxx</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
The order of the XML configuration is performed from bottom to top.
Web. XML filter configuration and execution sequence concepts