filter mapping to last path segment

1k views Asked by At

I am trying to map a filter to a specific url in web.xml. The problem is that there is a dynamic path segment in the url and I need to map my filter only to URLs ending with a specific path. For given URLs:

http://company.com/webApp/aaa/end
http://company.com/webApp/bbb/end
http://company.com/webApp/ccc/end

I need to map a servlet like:

<filter id="EndFilter">
    <filter-name>EndFilter</filter-name>
    <filter-class>com.company.EndFilter</filter-class>
</filter>

<filter-mapping>
    <filter-name>EndFilter</filter-name>
    <url-pattern>*/end</url-pattern> 
</filter-mapping>

I know that */ is not a valid wildcard but I dont know if this type of mapping is even possible. It is easy to map URLs with resources like pictures with endings *.png or *.jpeg wildcard but i can't find a way to map a simple url path segment.

1

There are 1 answers

0
pjanssen On BEST ANSWER

From the servlet 3.1 specification chapter 12:

In the Web application deployment descriptor , the following syntax is used to define mappings:

  • A string beginning with a / character and ending with a /* suffix is used for path mapping.
  • A string beginning with a *. prefix is used as an extension mapping.
  • The empty string ("") is a special URL pattern that exactly maps to the application's context root, i.e., requests of the form http://host:port/. In this case the path info is / and the servlet path and context path is empty string ("").
  • A string containing only the / character indicates the "default" servlet of the application. In this case the servlet path is the request URI minus the context path and the path info is null.
  • All other strings are used for exact matches only.

So it looks like it is not possible.