obelloc
obelloc

Reputation: 319

Is it possible for a Servlet filter to retrieve its url path?

I can map a single servlet to various url patterns in the web.xml file. When programming the servlet, I can then get which of those url patterns the request is matching, by getting the servlet path through request.getServletPath().

How can I achieve this with filters? When mapping a filter to various url patterns, is there a way to get what path the current request is matching?

Because my filter is currently working on content that is mapped to the DefaultServlet, the request.getServletPath() returns the whole path, and PathInfo is always null.

I am a newbie on servlet and filters, so I hope my question is clear and makes sense at all.

Upvotes: 2

Views: 2412

Answers (1)

BalusC
BalusC

Reputation: 1108672

No, there isn't. You have to determine it yourself based on the request URI and a predefinied set/list/map of all known/supported paths. You can if necessary set those paths as <init-param> of the filter and process it during the init() method so that you can reuse it in the doFilter() method.

Upvotes: 2

Related Questions