"Head first Servlets and JSP" NOTE 3

Source: Internet
Author: User

1, the existence of servlet is to serve customers. The servlet's task is to get a user's request and send back some responses.

    • Requests can be complex or simple, for example, "checkout my Shopping Cart," which carries some important data, you must know how to get the data, and, accordingly, the response may need to carry something, and you must know how to write the additional information to the response.
    • A servlet can either output a response directly to a Web container or forward a request to a JSP

2. Web containers, such as Tomcat, control the entire life of the servlet.

    1. The user clicks on a URLthat points to a servlet
    2. The container "sees" the URL pointing to a servlet, creating two objects:httpservletrequest,httpservletresponse
    3. The container creates a thread for the corresponding servlet and passes two objects into service (httpservletrequest req, HttpServletResponse resp )
    4. The service method calls the servlet's corresponding method (doget (httpservletrequest req, HttpServletResponse) based on the HTTP method (GET, post, etc.) sent by the client. Resp),doPost (httpservletrequest req, HttpServletResponse resp) such as
    5. The servlet responds to the customer by responding to the object, and the container returns the response to the customer.
    6. The service () thread ends, retains or cleans up the responding object, and the customer gets a response.

3. Mark Tomcat Official document Servlet API documentation

4, HttpServlet inheritance tree, interface

    • Java.lang.Object

Javax.servlet.GenericServlet

Javax.servlet.http.HttpServlet

Myservlet   

    • All implemented Interfaces:java.io.Serializable, Servlet, ServletConfig

Servlet interface: Includes three life cycle Methods

Genericservlet: Abstract classes, including most basic servlet behaviors, do not extend this class

HttpServlet: Emphasizing the HTTP features of the servlet

Myservlet: Overwrite the required HTTP methods, such as Dopost, etc.

5. Each request is run on a separate thread (not a process), and theservlet class will not have more than one instance! The servlet class will not have more than one instance!

6. When did the servlet class load and instantiate begin? Basically, when the container starts, there are exceptions, but it must be before the first customer requests a service.

7, before Init (), is only a normal object, when and only if an object has "servlet characteristics", can be called a servlet

8. Between the constructor and Init (), the servlet is in a state between life and death Schrödinger ' s Cat-wikipedia

"Head first Servlets and JSP" NOTE 3

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.