Servlet, session, JSP lifecycle __java

Source: Internet
Author: User
Tags server memory

The life cycle of the servlet:

1, the container starts, will read the Conf/server.xml file, to determine the boot port and Web application storage path

2. Web container startup reads the Web.xml file configuration information for each Web application and resolves the web.xml file. Get servlet configuration information.

Container to load and instantiate the servlet

(web.xml file Configuration servlet has a <load-on-startup> if greater than or equal to 0 then the startup container is instantiated, if it is a negative number or the default is the first request instantiation)

The container invokes the Init () method initialization

Call Service () method complete logic per request

Container Discard servlet call Destroy () method

1, 2, 3, 4, 6 execute only one line, and only 5 are executed on every request. And throughout the lifecycle, the Servlet object has only one single instance of multithreading.

Life cycle of Session:

Within the scope of a session. When the session object is generated, the object is bound to the client browser, and the session is valid for the timeout period, as long as the browser is not closed. When the browser is closed and a browser is reopened, the server will be allocated a new session object.

Because session is the object that is placed on the server side. So when the client closes the browser, it does not mean that the session object is destroyed. So at some time, be sure to destroy the session object to free up the server memory resources.


Life cycle of JSP:

1. The first time a Web container receives a request for a JSP page, it first automatically translates the JSP page into Java code.

2. The Web container is responsible for compiling the servlet code into byte code. With the source files in the same directory, in the JSP lifecycle, the entire translation and compilation steps occur only once

3. The Web container mounts the newly generated servlet class

4. The Web container creates a Servlet instance object when the first request arrives. There is only one object in the whole life

5, the Web container calls the Servlet sample Jspinit () method, JSP page load resource

6, each request arrives executes the _jspservice () method, the output content

7. The container invokes the Jspdestroy () method of the generated Servlet object, destroying the loaded resource





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.