Home > Java > javaTutorial > The life cycle of a JSP file is divided into several stages

The life cycle of a JSP file is divided into several stages

青灯夜游
Release: 2018-12-11 17:33:17
Original
6136 people have browsed it

The life cycle of a JSP file is divided into seven stages: parsing, compilation, class loading, instantiation, initialization, request processing, and destruction.

JSP files are saved with a .jsp extension, which allows the server to know that this is a JSP file and needs to go through several JSP life cycle stages. This article introduces the life cycle of JSP and gives you a preliminary understanding of the life cycle of JSP files. I hope it will be helpful to you. [Recommended related video tutorials: JSP Tutorial]

The life cycle of a JSP file is divided into several stages

Let’s take a closer look at each stage of the life cycle of a JSP file. What it does:

1. JSP file parsing (preprocessing) phase

When the client makes a request to the Server (server), the JSP file will first be transferred to the servlet container; then It is parsed in the servlet container and converted into a Servlet source file (.java file)

2. Compilation phase

Compiles the servlet source file (.java file) in the servlet container to generate a servlet class (.CLASS file)

The life cycle of a JSP file is divided into several stages
## JSP overall execution flow diagram

3, class loading phase

## class loader loading class file, container, container, container, container, container, container, container Will check if the servlet class is older than the jsp file (make sure the JSP file has been modified).

If the JSP file is modified, then the container will perform the conversion (convert JSP to Servlet) again, otherwise it will skip the conversion stage (i.e. if the JSP web page has not been modified, then it will not perform the conversion to Improve performance as this phase takes time).

4. Instantiation phase

Create the object that generates the Servlet and instantiate the servlet class

5. Initialization phase

After loading the JSP file, The container will call the jspInit() method to initialize the servlet instance before providing any services for the request (the Jsp container will only execute this stage if the instance of the servlet file is not running or it is older than the jsp file.)

public void jspInit(){
  // 初始化代码
}
Copy after login

6. Request processing phase

The container will create a new thread and call the _jspService() method, with the request (HttpServletRequest) and response (HttpServletRespnse) objects as parameters of the method.

void _jspService(HttpServletRequest req,HttpServletResponse res)
{ 
// 代码
}
Copy after login

7. Destruction phase

Call the jspDestroy() method to destroy instances of the servlet class

public void jspDestory()
{ 
//删除servlet类实例的代码
}
Copy after login

The life cycle of a JSP file is divided into several stages

Summary: That’s it for this article The entire content of the article is hoped to be helpful to everyone's study.

The above is the detailed content of The life cycle of a JSP file is divided into several stages. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template