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