"Javaweb Notes" Deployment Srevlet

Source: Internet
Author: User

Open the project's Web. xml file by adding two elements (<servlet-mapping> and <servlet >) to map the URL of the user access to the servlet.

Where <servlet-mapping> maps the user access to the URL to the servlet's internal name, the <servlet > element maps the servlet internal name to a servlet class name (package name + class name).

<servlet>    <servlet-name>HttpServletTest</servlet-name>    <servlet-class> Com.sss.httpservlettest</servlet-class></servlet>

Name: Specifies the name of the servlet, which must be unique within the same Web application.

Class: Specifies a class name (package name + class name)

==============================================================================================

<servlet-mapping>    <servlet-name>HttpServletTest</servlet-name>    <url-pattern>/ Httpservlettest</url-pattern></servlet-mapping>

Name: Must be the same as the name declared in the <servlet> element

Url-pattern: This address is the same as the requested address in the Web page

Note: After configuring a servlet-URL mapping, when the servlet container receives a request, first determine which Web application responds to the request, and then match the path of the request to the path of the servlet map.

===========================================================================================

Get initialization parameters

When you configure a servlet in Web. XML, you can configure some initialization parameters. In the servlet, these parameters can be obtained through the methods provided by the ServletConfig interface.

To set the initialization parameters of a servlet by adding <init-param> elements to the <servlet> element

1. Settings

  <servlet>    <init-param>        <param-name></param-name>        <param-value></ param-value>    </init-param>  </servlet>

Name: Name of parameter

Value: Values

2. Get initialization parameters

This.getinitparameter ("name"); À returns a string type

Name: Represents the name of the initialization parameter defined in the servlet.

"Javaweb Notes" Deployment Srevlet

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.