The servlet must know the details (i.)

Source: Internet
Author: User

The servlet must know the details (i) Having reviewed the servlet today, having had some programming experience, compared to the original learning servlet, the perspective of the servlet is different, initially just learning how to write a servlet,api how to use, Now we've learned more about servlets from a deeper point. The 1.servlet interface implements the HttpServlet inheritance Genericservlet,genericservlet implements the Servlet interface. 2. Life cycle approach where the servlet interface has several life-cycle methods:
Init (), service (), Destroy () is a three life cycle method (Life-cycle methods), the so-called life cycle approach, which is the method that must be executed at a particular stage during the servlet life cycle. Looking at the servlet API, you can see these three words: 1. The servlet is constructed,then initialized with the init Method.2. Any calls from clients to the service method was Handled.3.the servlet is taken out of service,then destroyed with the DES Troy Methon, then garbage collected and finalized. The main thing is to understand that three words: Normally, when Tomcat starts, the Servlet object is not created immediately, but the first time the client accesses the mapped directory configured by the servlet, the TomcatConstructs a Servlet object, invokes the Init method, and executes the service. Later, the Init method is not executed, the service is called directly, and the Destory method is called when Tomcat restarts or shuts down gracefully. Then, Init is used for the first time the client accesses the service, which is used every time the client accesses, and knows that every call to a servletobject thatServicemethod, a new thread is created. Destory is called when Tomcat shuts down normally. By the above description we can know that the servlet is only created at the time of the first visit and is not created later, so the servlet is a singleton. Servlet is a single instance of multithreading. We know that we write a servlet that does not need to implement the top-level interface servlet, just inherit the HttpServlet and implement the Doget and Dopost methods. The servlet interface is proposed to solve the data processing based on the request-response model, and does not involve the HTTP protocol and the related api,genericservlet is the generic servlet that implements the interface, and does not provide the API related to the HTTP protocol. In HttpServlet, the protocol-related APIs are introduced.
Note: If Loadonstartup is not configured, the servlet is created when the client accesses the servlet for the first time, and if it is configured, it is created when Tomcat is started.The above study, if there are errors, I hope you put forward, common improvement, thank you.


The servlet must know the details (i.)

Related Article

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.