BeginnersBook

  • Home
  • Java
    • Java OOPs
    • Java Collections
    • Java Examples
  • C
    • C Examples
  • C++
    • C++ Examples
  • DBMS
  • Computer Network
  • Python
    • Python Examples
  • More…
    • jQuery
    • Kotlin
    • WordPress
    • SEO
    • JSON
    • JSP
    • JSTL
    • Servlet
    • MongoDB
    • XML
    • Perl

Java Server Pages (JSP) Life Cycle

Last Updated: July 26, 2022 by Chaitanya Singh | Filed Under: JSP tutorial

JSP pages are saved with .jsp extension which lets the server know that this is a JSP page and needs to go through JSP life cycle stages.
In my previous post about JSP introduction, I explained that JSP is not processed as such, they first gets converted into Servelts and then the corresponding servlet gets processed by Server.

JSP Life Cycle

When client makes a request to Server, it first goes to container. Then container checks whether the servlet class is older than jsp page(  To ensure that the JSP file got modified). If this is the case then container does the translation again (converts JSP to Servlet) otherwise it skips the translation phase (i.e. if JSP webpage is not modified then it doesn’t do the translation to improve the performance as this phase takes time and to repeat this step every time is not time feasible)

The steps in the life cycle of JSP page are:

  1. Translation
  2. Compilation
  3. Loading
  4. Instantiation
  5. Initialization
  6. RequestProcessing
  7. Destruction

JSP Life Cycle

Let see the Life cycle of JSP in more detail:
1) As stated above whenever container receives request from client, it does translation only when servlet class is older than JSP page otherwise it skips this phase (reason I explained above).
2) Then the container –

  • compiles the corresponding servlet program
  • Loads the corresponding servlet class
  • Instantiates the servlet class
  • Calls the jspInit() method to initialize the servlet instance( JSP container will do this job only when the instance of servlet file is not running or if it is older than the jsp file.)
public void jspInit()
{
//code to intialize Servlet instances
}

3) A new thread is then gets created, which invokes the_jspService() method, with a request (HttpServletRequest) and response (HttpServletRespnse) objects as parameters -shown below.

void _jspService( HttpServletRequest req, HttpServletResponse res)
{
//code goes here
}

4) Invokes the jspDestroy() method to destroy the instance of the servlet class. code will look like below –

public void jspDestory()
{
//code to remove the instances of servlet class
}
❮ JSP IntroductionJSP in Eclipse IDE ❯

Top Related Articles:

  1. JSP Scriptlet Tag (Scripting elements)
  2. Introduction to Java Server Pages – JSP Tutorial
  3. Include Directive in JSP
  4. Solution – The superclass “javax.servlet.http.HttpServlet” was not found on the Java Build Path
  5. Config Implicit Object in JSP with examples

About the Author

I have 15 years of experience in the IT industry, working with renowned multinational corporations. Additionally, I have dedicated over a decade to teaching, allowing me to refine my skills in delivering information in a simple and easily understandable manner.

– Chaitanya

Comments

  1. Poornima says

    November 5, 2014 at 4:55 PM

    Thank you sir,

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

JSP Tutorial

  • Basics of JSP
  • Life cycle of JSP
  • JSP in Eclipse IDE

Scripting Elements

  • Scriptlet Tag
  • Expression tag
  • Declaration tag

Implicit Objects

  • Implicit Objects
  • JSP Request
  • JSP Response
  • JSP Config
  • JSP Application
  • JSP Session
  • JSP Out
  • JSP pageContext
  • JSP Exception
  • Validate session

JSP directives

  • JSP Directives
  • Include Directive

JSP Exception

  • Exception handling

JSP Action

  • Action tags
  • Include action
  • Forward action
  • useBean, setProperty & getProperty

Expression language

  • Expression language

JSP Custom Tags

  • Custom Tags
  • Custom tag example
  • JSP Interview Q

Copyright © 2012 – 2025 BeginnersBook . Privacy Policy . Sitemap