Define and map servlet in the web. xml file (1/3)

Source: Internet
Author: User

Define and map servlet in the web. xml file
In the Web. xml file, you must first define a servlet instance and then map the instance to one or more URL patterns.

1. Define the servlet instance:
<Servlet> The element defines a servlet instance. The <servlet> element must contain <servlet-Name> and <servlet-class> child elements, and may also contain other initialization parameters.
The <servlet-Name> element defines the unique name of the servlet instance. Each servlet instance must have a unique name. This name is only used for URL ing of this instance, so it does not have to be consistent with the servlet class or servlet URL.
The <servlet-class> element tells the servlet container how to build a servlet class instance. The <servlet-class> element consists of the servlet package name and Servlet class name. For example:
<Servlet>
<Servlet-Name> getstatus </servlet-Name>
<Servlet-class> status. createstatusservlet </servlet-class>
</Servlet>
 
The servlet Instance name does not need to be the same as the servlet class name. To load another instance of the same servlet class to the container, you only need to create another servlet Instance name. For example:
<Servlet>
<Servlet-Name> getstatus </servlet-Name>
<Servlet-class> status. createstatusservlet </servlet-class>
</Servlet>

<Servlet>
<Servlet-Name> fullstatus </servlet-Name>
<Servlet-class> status. createstatusservlet </servlet-class>
</Servlet>
 
Each <servlet> element may also include any number of <init-param> elements. The container sends the parameters to the respective servlet. Just as the command line parameters are passed to the entire program, the individual servlet requires their respective parameter names and parameter values. For example:

<Servlet>
<Servlet-Name> getstatus </servlet-Name>
<Servlet-class> status. createstatusservlet </servlet-class>
<Init-param>
<Param-Name> output </param-Name>
<Param-value> brief </param-value>
</Init-param>
</Servlet>

<Servlet>
<Servlet-Name> fullstatus </servlet-Name>
<Servlet-class> status. createstatusservlet </servlet-class>
<Init-param>
<Param-Name> output </param-Name>
<Param-value> verbose </param-value>
</Init-param>
</Servlet>

One <servlet> element can only define one servlet instance. In order for the container to send requests to the servlet, a servlet must be mapped to one or more URLs or called by other servlets or filters using the servlet name.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.