Advanced Java (2160707)

BE | Semester-4   Winter-2018 | 20-11-2018

Q4) (b)

Explain JSP life cycle phases.

Life Cycle Of JSP

  • A JSP life cycle can be defined as the entire process from its creation till the destruction.
  • It is similar to a servlet life cycle with an additional step which is required to compile a JSP into servlet.
  • A JSP page is converted into Servlet in order to service requests.
  • The translation of a JSP page to a Servlet is called Lifecycle of JSP.
JSP Life Cycle
(Figure: JSP Life Cycle)

JSP Lifecycle steps

  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
  • Web Container translates JSP code into a servlet source(.java) file.
  • Then compiles that into a java servlet class (bytecode).
  • In the third step, the servlet class bytecode is loaded using classloader in web container.
  • The Container then creates an instance of that servlet class.
  • The initialized servlet can now service request.
  • For each request the Web Container call the _jspService() method.
  • When the Container removes the servlet instance from service, it calls the jspDestroy() method to perform any required clean up.