Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Url Matching Algorithm Used By Tomcat for web.xml

Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to set up a simple java program that can do the following:

* Takes in a ' given url' such as '/places/australia'
* Takes in a list of URL mappings such as ["*.do", *jsp, "/places", "/places/aust"]

I want to do this to investigate exactly which given URL's will match against the servlet and filter mappings given in a web.xml file. My initial guess was to use the standard Java Pattern and Matcher classes as per below:

However when I ran the code I got the following exception:

This would imply that the standard java regex classes are not used for matching the URL's in web.xml.

Does anyone know of the class library tomcat or a similar container uses to determine if a given url matches the web.xml mappings?
Ranch Hand
Posts: 116
Eclipse IDE Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The matching algorithm is specified in the servlet specification and isn't (or shouldn't be) Tomcat specific. I would seriously doubt that it uses regex libs for a couple of reasons; one, the pattern matching is pretty simple and regex would be overkill, two, the URL matching predates the regex libs. There are some rules about what kind of matching takes precedence that could not be expressed in regex syntax also.

If memory serves correct, there are four kinds of mapping; path, extension, default and exact.
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.
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.

Exact match takes precedence over path and extension.
Path match takes precedence over extension.
Default servlet matches anything else.
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic