Search This Blog

Monday 20 February 2017

JSP Lifecycle

JSP Lifecycle

The lifecycle of a JSP is the entire process from its creation till the destruction which is similar to a servlet life cycle with an additional step, which translates the JSP into a Servlet.
Following are the JSP Lifecycle phases.
1.     Translation of JSP to Servlet code.
2.     Compilation of Servlet to bytecode.
3.     Loading Servlet class.
4.     Creating servlet instance.
5.     Initialization by calling jspInit() method
6.     Request Processing by calling _jspService() method

7.     Destroying by calling jspDestroy() method
JSP Lifecycle
JSP Lifecycle

JSP Translation and Compilation
When a user request for a JSP, the JSP engine first checks to see whether it needs to compile the page. If the page has never been compiled, or if the JSP has been modified since it was last compiled, the JSP engine does the following
1.   Parse the JSP
2.   Transforms the JSP to a Servlet
3.   Compile the Servlet (.java) file to a class file.


JSP Initialization
Before servicing any request the web container loads the JSP and invokes jspInit() method. Initialization is performed only once, just as with servlets init() method. If you need to perform any JSP-specific initialization, you need yo override the jspInit() method.

JSP Service
Once the JSP page has been loaded and initialized, the JSP engine invokes the _jspService() method in the JSP.
The _jspService() method takes an HttpServletRequest and an HttpServletResponse as its parameters.
The _jspService() method of a JSP is invoked once per request and is responsible for generating the response for that request.

JSP Destruction
The destruction phase of the JSP life cycle represents when a JSP is being removed from use by a container.
The jspDestroy() method is the JSP similar to the destroy method for servlets. We need to Override jspDestroy() method when we need to perform any cleanup operation, such as releasing database connections or closing files which were opened.

4 comments:

  1. Thank you for sharing this blog. This blog will help to improve my knowledge.
    JAVA J2EE Training Institutes in Chennai | Core Java training

    ReplyDelete
  2. I just needed to record a speedy word to express profound gratitude to
    you for those magnificent tips and clues you are appearing on this
    site.
    Java and J2EE Training in Chennai | Java and J2EE Training Institutes in Chennai

    ReplyDelete
  3. i like the valuable information you provided. it is very informative and creative content.best J2EE training institute

    ReplyDelete
  4. Hey, would you mind if I share your blog with my twitter group? There’s a lot of folks that I think would enjoy your content. Please let me know. Thank you.
    Java Training in Chennai | J2EE Training in Chennai | Advanced Java Training in Chennai | Core Java Training in Chennai | Java Training institute in Chennai

    ReplyDelete