1

I'm trying to set up a servlet so that any requests for /foo/* will go to my Foo servlet, except for requests in the form of /foo/bar/*, which go to the Bar one. However, I want /foo/bar to go to the Foo servlet, not the Bar one. Is there a way to do this with just url-patterns in web.xml?

My mappings:

<servlet-mapping>
    <servlet-name>Bar</servlet-name>
    <url-pattern>/foo/bar/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
    <servlet-name>Foo</servlet-name>
    <url-pattern>/foo/*</url-pattern>
</servlet-mapping>

I've tried removing the asterisks and trying a few other patterns, but the only way I can see to do this is to have a specific mapping for /foo/bar, though it seems like there should be a better way.

CSturgess
  • 1,547
  • 2
  • 13
  • 29

1 Answers1

0

If you are using servlet specification v2.5 or above then you could provide multiple url-pattern elements for the same servlet-mapping like:

<servlet-mapping>
  <servlet-name>Foo</servlet-name>
  <url-pattern>/foo/*</url-pattern>
  <url-pattern>/foo/bar</url-pattern>
</servlet-mapping>
S. Pauk
  • 5,208
  • 4
  • 31
  • 41