Multiple filters with same url mapping

mosaad picture mosaad · Nov 15, 2013 · Viewed 17.3k times · Source

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>

Answer

Suresh Atta picture Suresh Atta · Nov 15, 2013

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