Open In App
Related Articles

Life cycle of JSP

Improve Article
Save Article
Like Article

A Java Server Page life cycle is defined as the process that started with its creation which later translated to a servlet and afterward servlet lifecycle comes into play. This is how the process goes on until its destruction.

Lifecycle of JSP

Following steps are involved in the JSP life cycle: 

  1. Translation of JSP page to Servlet
  2. Compilation of JSP page(Compilation of JSP into
  3. Classloading ( to test.class)
  4. Instantiation(Object of the generated Servlet is created)
  5. Initialization(jspInit() method is invoked by the container)
  6. Request processing(_jspService()is invoked by the container)
  7. JSP Cleanup (jspDestroy() method is invoked by the container)

We can override jspInit(), jspDestroy() but we can’t override _jspService() method.

Translation of JSP page to Servlet: 

This is the first step of the JSP life cycle. This translation phase deals with the Syntactic correctness of JSP. Here test.jsp file is translated to

  1. Compilation of JSP page: Here the generated java servlet file ( is compiled to a class file (test.class). 
  2. Classloading: The classloader loads the Java class file into the memory. The loaded Java class can then be used to serve incoming requests for the JSP page.
  3. Instantiation: Here an instance of the class is generated. The container manages one or more instances by providing responses to requests.
  4. Initialization: jspInit() method is called only once during the life cycle immediately after the generation of the Servlet instance from JSP.
  5. Request processing: _jspService() method is used to serve the raised requests by JSP. It takes request and response objects as parameters. This method cannot be overridden. 
  6. JSP Cleanup: In order to remove the JSP from the use by the container or to destroy the method for servlets jspDestroy()method is used. This method is called once, if you need to perform any cleanup task like closing open files, or releasing database connections jspDestroy() can be overridden.
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 10 May, 2023
Like Article
Save Article
Similar Reads
Complete Tutorials