Servlet Matching Procedure
A request may match more than one servlet-mapping in a given context. The servlet container uses a straightforward matching procedure to determine the best match. The matching procedure has four simple rules, applied in the order described below:
1. The container prefers an exact path match over a wildcard path match.
2. The container prefers to match the longest pattern.
3. The container prefers path matches over file type matches.
4. If no valid match is found, the container matches to <url-pattern>/</url-pattern>, the default servlet (see Default Servlet).
NOTE: The container uses case-sensitive string comparisons for matching.
For example, a context web.xml file might map the home page for an online catalog to one pattern and the search page for the catalog to a different pattern, as shown below:
 
<servlet-mapping>
<servlet-name>catalogBrowse</servlet-name>
<url-pattern>/Catalog/*</url-pattern>
</servlet-mapping>
 
<servlet-mapping>
<servlet-name>catalogSearch</servlet-name>
<url-pattern>/Catalog/search/*</url-pattern>
</servlet-mapping>
Figure 4 illustrates the matching process if the request URL is http://example.com/servlets/Catalog/search/?word=Grid.
Figure 4 – URL pattern matching
Two mappings are valid for this request, the first and third shown. Since the container prefers to match the longest pattern, a URL that includes /Catalog/search/ always matches the mapping for catalogSearch rather than the mapping for catalogBrowse