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 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 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 ...

Get Java Servlet & JSP Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.