2. Map Servlets to URLS Elements provide a URL Pattern for a servlet instance. element must contain elements and elements. elements must be consistent with the element defined by a Web.xml file element. Since the same servlet in a container may have multiple instances running, the container uses to determine a servlet mapping. The URL / Status / * of the following example is mapped to a servlet called getStatus. If a servlet is defined by a container in http: //example.roguewave.com/, then this element tells the container GetStatus Servlet to access http: //example.roguewave.com/examples/status with Requests at the beginning below.
getStatus servlet-name> / status / * url-pattern> servlet-mapping>
A servlet can accept any quantity URL Patterns' Requests. The following example shows two different Pattern for the same servlet instance:
getStatus servlet-name> / status / * url-pattern> servlet-mapping>
getStatus servlet-name> / briefStatus / * url-pattern> servlet-mapping>
Different Pattern can map to the same servlet, but the same pattern cannot map different servlets. If a URL-Pattern in the same web.xml file is mapped to a different servlet, the container cannot guarantee which servlet call to a request.
2.1 URL PATTERN Syntax:
Each character in a URL Pattern must be strict in the URL PATH. By two exceptions, in a Pattern end, / * matches any character after this point; *. Extension matches any file name with this extension. For example: Server EXAMPLE.COM Path / Examples Matching Matches Uplide / Status / * url-pattern> can have the following match: http: //example.com/examples/status/synopsishttp: // Example.com/examples/status/complete?date=todayhttp: //example.com/examples/status
Match: http://example.com/examples/server/status
Server EXAMPLE.COM Path / Examples Matching Matches *. Map url-pattern> can have the following match: http: //example.com/examples/us/oregon/portland.maphttp: / /example.com/example.MapHttp: //example.com/examples/paris.france.map does not match http: //example.com/examples/us/oregon/portland.map // Extension The uppercase http: //example.com/examples/interface/description/mail.mapi // extension is Mapi instead of the Map of different filters in the same web.xml file to use the same URL-PATTERN. In this case, each Filter that matches the Request will handle this Request. Instead, there is no two servlets in the same web application to map to the same URL-Pattern, and if a URL-Pattern in the same web.xml file is mapped to different servlets, the container cannot guarantee which servlet calls to a Request call. However, the two servlets can be identical to the partially consistent URL-Pattern (ie / * or * .ext1) so that the container call which servlet is determined by the matching process. 2.2 Servlet matching procedure A request may match more than one servlet mapping. The container uses the matching process of StraightForward to determine which servlet matches. There are four simple rules: 1> strict matching is preferred to match the match *; 2> The longest Pattern takes precedence over other Pattern; 3> Path matching is preferred to match file types; URL-PATTERN> always matches other Pattern matching request.
For example, the web.xml file may map the home page of the online directory to a Pattern, and map the online directory to another PATTERN:
catalogbrowse servlet-name> / catalog / * url-pattern> servlet-mapping>
catalogsearch servlet-name> / catalog / search / * url-pattern> servlet-mapping>
The figure below describes the matching process: Since the longest Pattern takes precedence over other Pattern, the URL containing / catalog / search / SEARCH is always mapped to CatalogSearch, not CatalogBrowse.
2.3 Default servlet: The Pattern match containing / URL-PATTTERN> does not have other Pattern matching request. This is the default mapping. The servlet called the default map called the default servlet. The default mapping is general to a first page of an app. Explicitly provide a default mapping to ensure that incorrect URL Requests is mapped to Return Error that can be processed by the application rather than gives a return error. The following element will be mapped to Welcome Servlet instance Welcome servlet-name> / url-pattern> servlet-mapping > Web.xml containing this element will give any other mapping that cannot be processed to Welcome Servlet.