aloo
aloo

Reputation: 5389

How to NOT run servlet filters for specific url-patterns?

I'd like to create a servlet filter that applies to all my URL paths except for a few a specify (or ideally specified by a regex).

Is that possible? Unfortunately I can't change the paths such that all of my other URLs start with something common....

Upvotes: 0

Views: 1313

Answers (1)

Christopher Schultz
Christopher Schultz

Reputation: 20837

You can't do this via spec-compliant configuration. You do have a couple of options:

  1. Re-write your <filter-mapping>s so that they are much more specific (e.g. /foo becomes /foo/bar and /foo/baz but not /foo/foo).
  2. Alter the code in the filter so that it knows about a list of "excludes" URI patterns. You can even use <init-param> if you want to configure them in web.xml, but you'll have to do the real work yourself.
  3. Add a set of <filter-mapping>s and <servlet-mapping>s that do share a common URI prefix and start using those (leaving the old mappings in effect).

Upvotes: 1

Related Questions