| C H A P T E R 11 |
|
Mapping Requests To Servlets |
The mapping techniques described in this chapter are required for web containers mapping client requests to servlets.
Upon receipt of a client request, the web container determines the web application to which to forward it. The web application selected must have the longest context path that matches the start of the request URL. The matched part of the URL is the context path when mapping to servlets.
The web container next must locate the servlet to process the request using the path mapping procedure described below.
The path used for mapping to a servlet is the request URL from the request object minus the context path and the path parameters. The URL path mapping rules below are used in order. The first successful match is used with no further matches attempted:
1. The container will try to find an exact match of the path of the request to the path of the servlet. A successful match selects the servlet.
2. The container will recursively try to match the longest path-prefix. This is done by stepping down the path tree a directory at a time, using the / character as a path separator. The longest match determines the servlet selected.
3. If the last segment in the URL path contains an extension (for example, .shtml), the servlet container will try to match a servlet that handles requests for the extension. An extension is defined as the part of the last segment after the last “.” character.
4. If neither of the previous three rules result in a servlet match, the container will attempt to serve content appropriate for the resource requested. If a “default” servlet is defined for the application, it will be used.
The container must use case-sensitive string comparisons for matching.
In the web application deployment descriptor, the following syntax is used to define mappings:
A servlet container is allowed to make implicit mappings as long as explicit mappings take precedence. For example, an implicit mapping of *.shtml could be mapped to include functionality on the server. If a *.shtml mapping is defined by the web application, its mapping takes precedence over the implicit mapping.
Consider the set of mappings in TABLE 11-1.
/foo/bar/* |
servlet1 |
/baz/* |
servlet2 |
/catalog |
servlet3 |
*.bop |
servlet4 |
The behavior shown in TABLE 11-2 would result.
Note that in the case of /catalog/index.html and /catalog/racecar.bop, the servlet mapped to “/catalog” is not used because the match is not exact.
Copyright © 2009 Sun Microsystems, Inc. All rights reserved.