Multiple filters with same url mapping

2020-06-08 19:05发布

问题:

Is it possible to use two filters that have the same url-mapping?

<filter>
 <filter-name>TeeFilter</filter-name>
 <filter-class>filter1r</filter-class>
</filter>
<filter-mapping>
 <filter-name>TeeFilter</filter-name>
 <url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<display-name>CredentialsFilter</display-name>
<filter-name>CredentialsFilter</filter-name>
<filter-class>filter2</filter-class>
</filter>
<filter-mapping>
 <filter-name>CredentialsFilter</filter-name>
 <url-pattern>/*</url-pattern>
</filter-mapping>

回答1:

Yes. You can.

The order you placed in web.xml will execute.

So here,

First control goes to TeeFilter and then to CredentialsFilter.

And if you want to execute CredentialsFilter first, change the order in web.xml