5.3. Assigning Names and Custom URLs

One of the most common tasks that you perform in web.xml is giving names and custom URLs to your servlets or JSP pages. You use the servlet element to assign names; you use the servlet-mapping element to associate custom URLs with the name just assigned.

Assigning Names

In order to provide initialization parameters, define a custom URL, or assign a security role to a servlet or JSP page, you must first give the servlet or page a name. You assign a name by means of the servlet element. The most common format includes servlet-name and servlet- class subelements (inside the web-app element), as follows.

 <servlet> <servlet-name>Test</servlet- name> <servlet-class>moreservlets.TestServlet</servlet-class> </servlet> ...

Get More Servlets and JavaServer Pages™ 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.