Name

<servlet>

Synopsis

The <servlet> element can describe a servlet class or a JSP page, to give it a short name and to specify initialization parameters:

<servlet>
  <servlet-name>
    purchase
  </servlet-name>
  <servlet-class>
    com.mycorp.servlets.PurchaseServlet
  </servlet-class>
  <init-param>
    <param-name>maxAmount</param-name>
    <param-value>500.00</param-value>
  </init-param>
</servlet>
  
<servlet>
  <servlet-name>
    order-form
  </servlet-name>
  <jsp-file>
    /po/orderform.jsp
  </jsp-file>
  <init-param>
    <param-name>bgColor</param-name>
    <param-value>blue</param-value>
  </init-param>
</servlet>

The same servlet class (or JSP page) can be defined with multiple names, typically with different initialization parameters. The container creates one instance of the class for each name.

The <load-on-startup> subelement can tell the container to load the servlet when the application is started. The value is a positive integer, indicating when the servlet is to be loaded relative to other servlets. A servlet with a low value is loaded before a servlet with a higher value:

<servlet>
  <servlet-name>
    controller
  </servlet-name>
  <servlet-class>
    com.mycorp.servlets.ControllerServlet
  </servlet-class>
  <load-on-startup>1</load-on-startup>
</servlet>

The <icon>, <display-name>, and <description> elements can describe the servlet or JSP page the same way as these elements can describe the application.

<security-role-ref> elements, combined with <security-role> elements, can link a security role name used in a servlet as the ...

Get JavaServer Pages, Second Edition 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.