NonStop Servlets for JavaServer Pages (5.0) System Administrator's Guide

Configuring NSJSP
NonStop Servlets for JavaServer Pages (NSJSP) System Administrator’s Guide525644-002
3-20
Map Requests to Applications and Servlets
Map Requests to Applications and Servlets
Mapping requests to servlets is closely linked to the concept of a context path.
The application name and the context path lead to the application subdirectory. The
<servlet-mapping> and <servlet> tags are needed to find a servlet or JSP within
that application.
The location of the application directory (and, therefore, the servlet or JSP) is
determined in the docBase attribute of a Context if an absolute path is specified or
then as a relative path to the value of the appBase attribute of the Host this Context
belongs to.
The servlet or JSP could be any name (given the <servlet-name> and <servlet-
class> XML elements of the web.xml file) not just the class name. Using these
elements allows separation between the web pages (using a servlet name) and the
underlying Java code (using the class name), and makes maintenance easier.
URL Mapping to the Application
In a NSJSP container, each application is associated with a context, and all resources
exist relative to that context. The context path starts at the root level of the application
directory. In Configuring Web Applications on page 3-14, the context is /myapp1, the
name of the application.
Consider the URL that locates that context:
http://www.hostname.com/myapp1
The http://www.hostname.com is a URL for the HTTP scheme located at
www.hostname.com. The URI path is /myapp1. Together they form the URL.
As well as the www.hostname.com notation shown above, URLs can take the form
http://hostname:portnumber/myapp1
Each web application must be mapped to a unique URL path prefix, for instance,
/myapp1. The NSJSP container uses this prefix to map requests to resources within
the web application. The path name serves as the document root for serving resources
within the application.
URL Mapping to the Servlet
The mapping process has two parts. The first part is to provide servlet name and,
optionally, an alias for the full servlet class name. Therefore you could have a servlet
name such as start that refers to the servlet class startCartRequest.
The second part is to use the <servlet-mapping> elements of the deployment
descriptor to provide a more complex mapping than the usual inclusion of servlet name
(or class name) in the URL.
Example 3-13 is a sample fragment of a web.xml file that maps any URL containing
the application name to a specific servlet.