Life Cycle of a JSP Page - Javastudypoint

Thursday, November 8, 2018

Life Cycle of a JSP Page

In the previous tutorial, we have learned What is JSP. Basically, JSP stands for Java Server Pages. In this tutorial, we will learn about the life cycle of JSP. There are 7 steps involved in translating a JSP page into a servlet code. We will learn these steps in detail. But first, understand what is JSP life cycle?


What is JSP life cycle?

JSP life cycle is the process of translation of a JSP page into servlet code. The container is responsible for translating the JSP into a runnable servlet code. The role of the container is to take a JSP file then perform various tasks such as validation and generate the appropriate servlet code.

Read: Introduction to JSP

JSP life cycle Diagram is given below:
Life Cycle of JSP Page
JSP Life Cycle

Steps involved in JSP life Cycle:

There are 7 steps involved in translating a JSP page into a servlet code. we will discuss these steps in JSP life cycle.

1. Translation process

In this process, the container translates a JSP page into servlet code.

2. Compilation process- 

In the compilation process, the java servlet file is compiled into a class file.

3. Loading process

In this process, the servlet class is loaded into the container.

4. Instantiation process

In this process, an instance of the servlet is created.

5. Initialization process-

JSP Page is initialized by _jspinit() method.It allows the page author to provide initialization to the  JSP Page. This method will redefine the init() method, which is defined in the servlet class.All the method in servlets,including getServletConfig(),are available,when this method is called.This method is called only once during the JSP life cycle.

6. Request process

The _jspservice () method is used for request processing. This method is invoked by the container. This method is called to handle each request. The response is produced from within this method and then returned to the container so that it can be passed back to the client.

7. Destroy process-  

The _jspDestroy() method is used to destroy the JSP Page. The destroy() method defined in the servlet class is redefined by this method. If any cleanup is required, then the page author can define this method. This method is called only once during JSP page Life Cycle.


You may also like:


No comments:

Post a Comment