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?
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.
subject: Url Matching Algorithm Used By Tomcat for web.xml