I want some concrete filter to be applied for all urls except for one concrete (i.e. for /* except for /specialpath).
Is there a possibility to do that?
sample code:
<filter>
<filter-name>SomeFilter</filter-name>
<filter-class>org.somproject.AFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>SomeFilter</filter-name>
<url-pattern>/*</url-pattern> <!-- the question is: how to modify this line? -->
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
The standard Servlet API doesn’t support this facility. You may want either to use a rewrite-URL filter for this like Tuckey’s one (which is much similar Apache HTTPD’s
mod_rewrite), or to add a check in thedoFilter()method of the Filter listening on/*.You can if necessary specify the paths-to-be-ignored as an
init-paramof the filter so that you can control it in theweb.xmlanyway. You can get it in the filter as follows:If the filter is part of 3rd party API and thus you can’t modify it, then map it on a more specific
url-pattern, e.g./otherfilterpath/*and create a new filter on/*which forwards to the path matching the 3rd party filter.To avoid that this filter will call itself in an infinite loop you need to let it listen (dispatch) on
REQUESTonly and the 3rd party filter onFORWARDonly.See also: