Original content: Https://www.tutorialspoint.com/jsp/jsp_life_cycle.htm
In this chapter, we will discuss the life cycle of the JSP.
The key to understanding the low-level capabilities of JSP is to understand the simplest life cycle that they follow.
The life cycle of a JSP refers to the process of "it from creation to destruction".
This process is similar to the life cycle of the servlet,
Just add an extra step and you need to compile the JSP into a servlet first.
The path that the JSP follows
Here is the path that the JSP follows −
- Assembly
- Initialization
- Perform
- Clean
The 4 main stages of the JSP life cycle are very similar to the life cycle of the servlet. 4 stages as shown −
Assembly
When a browser requests a JSP page, the JSP engine first checks to see if it needs to compile the page. If the page has never been compiled, or if the page has been modified, the JSP engine will compile the page.
This compilation process consists of the following three steps-
- Parse the JSP.
- Convert the JSP into a servlet.
- Compile the servlet.
Initialization of the JSP
When the container loads a JSP, the first call is the Jspinit () method. If you need to do something at this time, please rewrite this method-
Public void Jspinit () { // initialization code ...}
Typically, initialization is only performed once, at which point you can: Initialize a database connection, open some files, create a "query table", etc.
Execution of JSP
At this stage, the JSP will deal with the request.
Whenever the browser requests a JSP page that has been initialized,
The JSP engine will call the _jspservice () method in the JSP, which receives a httpservletrequest and a httpservletresponse As a parameter, as shown below-
void _jspservice (httpservletrequest request, httpservletresponse response) { // Service Handling code ...}
The _jspservice () method of the JSP generates the corresponding response based on the specific HTTP request. These HTTP requests may be GET, POST, delete, and so on.
Removal of JSP
When the JSP is no longer being used, it is removed by the container.
You can do something about the JSP cleanup by overwriting the method, such as closing the database connection, closing the file, etc.
Public void Jspdestroy () { // Your cleanup code goes here.}
JSP Note 05--life cycle (RPM)