Life Cycle of a JSP Page

Prashant Srivastava
2 min readDec 16, 2018

--

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.

JSP life cycle Diagram is given below:

JSP Life Cycle

Steps involved 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, a 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 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.

--

--