From the Servlet 3.0 specification , here is how the web container should find the servlet after receiving the request (highlighting mine):
The path used to map to the servlet is the request URL from the request object minus the context path and path parameters. The following are URL mapping rules. The first successful match is used without any subsequent attempts :
- The container will try to find the exact match of the request path to the servlet path. A successful match chooses a servlet.
- The container will recursively try to match the longest path prefix. This is done by moving down the path tree to the directory at that time, using the / character as a path separator. The longest match defines the selected servlet.
- If the last segment of the URL path contains an extension (for example, .jsp), the servlet container will try to map the servlet that processes the extension requests. An extension is defined as part of the last segment after the last. character.
- If none of the previous three rules leads to a servlet match, the container will try to serve the content corresponding to the requested resource. If for the application, it will be used. Many containers provide an implicit servlet by default for serving content.
The container must use case-sensitive string matching for matching.
You should also look at the specification of mappings (see below):
In a web application deployment descriptor, the following syntax is used to define mappings:
The line begins with the character '/' and ends with the suffix '/*' used to display the path.
A line starting with the prefix '*.' , is used as a display of extensions.
An empty string ("") is a special URL pattern that exactly matches the root of the application context, that is, requests of the form http://host:port/<contextroot>/ . In this case, the path information '/' and the servlet path and the context path are the empty string ("") .
A line containing only the '/' character points to the "default" application servlet. In this case, the servlet path is to request the URI minus the context path, and the path information is null.
All other lines are used only for exact matches.
Let's consider now examples. Consider the following set of mappings:
Path pattern servlet
/ foo / bar / * servlet1
/ baz / * servlet2
/ catalog servlet3
* .bop servlet4
The following behavior will result in:
Incoming Path Servlet Handling Request
/foo/bar/index.html servlet1
/foo/bar/index.bop servlet1
/ baz servlet2
/baz/index.html servlet2
/ catalog servlet3
/catalog/index.html "default" servlet
/catalog/racecar.bop servlet4
/index.bop servlet4
Note that in the case of /catalog/index.html and /catalog/racecar.bop , the servlet displayed on "/catalog" is not used because the match is not exact.
Now let's get to your problem :)
/path/test belongs to the fifth point of the map specification. This means that only paths ending in /path/test will target servlet1 .
However, /path/test/* is suitable for the first point of the same specification. It means that:
.../path/test will be handled by servlet1 and
.../path/test/abc will be handled by servlet2
This was verified by me in a test application.
Nishant Shreshth Mar 13 '13 at 13:24 2013-03-13 13:24
source share