Chapter 3. Naming Your Servlets
An important web application configuration task is to create the path by which your servlet is requested by web users. This is what the user types into the address field of his browser in order to make a request to the servlet. While this is sometimes the full name of the servlet, that convention often results in an awkward URI. For example, a web site might have a servlet that dynamically assembles a “Resources” page, instead of a static resources.html page. Using the full servlet name, the request URL might be http://www.myorganization.com/servlet/com.organization.servlets.resources.ResourceServlet. This is quite a path to type in; it makes much more sense to map this to a servlet path, which is an alias for the servlet. Using the servlet path, the (new) address for the dynamic page might be http://www.myorganization.com/resources. The servlet path, in this case, is /resources.
This servlet path is also the identifier used by
other servlets or JSPs that forward
requests to this particular servlet, as
well as the address that an HTML form
tag uses in its
attribute to launch parameter names and
values toward the servlet. The servlet
specification offers an intuitive and
flexible way to map HTTP requests to
servlets in the
This chapter describes how you can use the web.xml deployment descriptor to create one or more aliases (servlet paths) to your servlet. It also discusses how to invoke the servlet ...