JSP Note 05--life cycle

Source: Internet
Author: User

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)

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.