[Java.web] Some details of the Servlet

Source: Internet
Author: User

This article comes from the Biography of Wisdom podcast video ppt

1. Because the client accesses resources in the Web server through a URL address, the servlet program must

The program maps to a URL address, which is done using the <servlet> elements and <servlet-mapping> elements in the Web. xml file.

2. The <servlet> element is used to register a servlet, which contains two primary child elements:<servlet-name> and <servlet-class>

Used to set the registration name of the servlet and the full class name of the servlet, respectively.

3. An <servlet-mapping> element is used to map an external access path to a registered servlet that contains two child elements:

<servlet-name> and <url-pattern>, respectively, to specify the name of the servlet's registration and the external access path of the servlet.

4. The same Servlet can be mapped to multiple URLs, that is, the set values of the <servlet-name> child elements of multiple <servlet-mapping> elements

Can be a registered name for the same Servlet.

5. You can also use the * wildcard character in the URL that the Servlet maps to, but there are only two fixed formats:

One format is "*. Extension", and the other is preceded by a forward slash (/) and ends with (/*). Use * can do pseudo-static website.

6. Examples of mapping matching priorities:

Servlet1 Mapping to/abc/*

Servlet2 Map to/*

Servlet3 Mapping to/ABC

Servlet4 Mapping to *.do

When the request URL is/abc/a.html, both 1 and 2 match, and the Servlet engine calls 1.

When the request URL is/abc, 1, 2, and 3 match, and the Servlet engine calls 3.

When the request URL is/abc/a.do, both 1 and 4 match, and the Servlet engine calls 1.

When the request URL is/a.do, both 2 and 4 match, and the Servlet engine calls 2.

When the request URL is/xxx/yyy/a.do, both 2 and 4 match, and the Servlet engine calls 2.

7. A servlet is a Java class that is called by another Java program (Servlet engine) and cannot run independently, it runs entirely by the

Servlet engine to control and dispatch.

8. Multiple servlet requests for the client, typically, the server creates only one Servlet instance object, which means

Once a Servlet instance object is created, it resides in memory and serves subsequent requests until the Web container exits.

The Servlet instance object will not be destroyed.

9. The servlet's Init method is called only once throughout the servlet's life cycle.

Each access request to a servlet causes the servlet engine to invoke the Servlet's service method once.

For each access request, the Servlet engine creates a new HttpServletRequest request object and a new

HttpServletResponse the Response object, and then passes the two objects as arguments to the service () of the Servlet that it invokes

method, and the service method calls the Doxxx method, respectively, according to the requested mode.

[Java.web] Some details of the Servlet

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.