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 action 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 web.xml deployment descriptor.
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 with other types of URLs, such as one that looks like a JSP page request (e.g., info .jsp ) or one that looks like an HTML page request ( info.html ). Recipe 3.5 also describes how to access a servlet without a mapping in web.xml , for example, for the developer who wants to debug her servlet without modifying the web.xml file.
Finally, Recipe 3.7, Recipe 3.9, and Recipe 3.10 show how to map all requests to one "controller" servlet (Recipe 3.7), restrict the requests for certain servlets to authenticated users (Recipe 3.9), and block all requests to certain servlets except those forwarded from the controller (Recipe 3.10).