!DOCTYPE html> JSP Life cycle tutorial| java tutorials


❮ Previous Next ❯

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:

c-question

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.

jspInit():

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()
{
//code
}

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.

jspService():

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)
{
//code
}

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.

jspDestroy():

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()
{
//code
//code
}

❮ Previous Next ❯

Follow Us




  Tutorials

Popular Links

Contact Us

address Plot No-741,2ND Floor
Opp. Bhagabati Temple,Jayadev Vihar
      Bhubaneswar-751013
      Email: info@silantechnology.com
      Phone: 0674-2361252
address
39877, sundale dr, apt#101, Fremont, California 94538, USA
       Phone: +1(262)388-7619

facebook twitter google linked in

© 2018 Silan Technology. All Rights Reserved