JSP Life cycle

JSP life cycle follows some stages like servlet. JSP are created to support the creating of presentation layer.

Let's give a closer look:


  • JSP is translating to Servlet.
  • Compilation of Servlet into .class file.
  • class file is loaded by the class loader sub system.
  • Servlet instance is created.
  • jspInit() method is invoked
  • _jspService() method is invoked
  • jspDestroy() method is invoked


Here the JSP page is first converted into Servlet(.java) file by the JSP translator which is a part of web server. Then the .java file is compiled by java compiler to generate .class file which is loaded by the class loader sub system. Then the Servlet instance is created for whole application which is called as Servlet context object. Then JSP life cycle methods jspInit(), _jspService() and jspDestroy() is invoked by the web container to execute a JSP page.


When web container loads a JSP, jspInit() method is invoked before servicing any requests. If you need to perform JSP-specific initialization, override the jspInit() method:

public void jspInit()

Typically initialization is performed only once and as with the servlet init method, you generally initialize database connections, open files, and create lookup tables in the jspInit method.


This phase of the JSP life cycle provides the service as per the request. Whenever a browser requests a JSP and the page has been loaded and initialized, the JSP engine invokes the jspService() method in the JSP. The jspService() method takes an HttpServletRequest object and an HttpServletResponse object as its parameters as follows:


void _jspService(HttpServletRequest request, HttpServletResponse response)

The jspService() method of a JSP is invoked once per a request and is responsible for generating the response for that request and this method is also responsible for generating responses to all seven of the HTTP methods ie. GET, POST, DELETE etc.


When a JSP is being removed from use by a container, then jspDestroy() method is invoked. The jspDestroy() method is the JSP equivalent of the destroy method for servlets. Override jspDestroy when you need to perform any cleanup, such as releasing database connections or closing open files. The jspDestroy() method has the following form:

public void jspDestroy()

Our Services:

Java Training | Python Training | Machine Learning with Python Training | Deep Learning with Python Training | Data Science with Python Training | Projects

SILAN Technology, BBSR
Call to: 0674-2361252