Explain the life cycle of a JSP page?


Explain the life cycle of a JSP page?

Ninja Asked on 18th September 2018 in Jsp.
Add Comment
1 Answer(s)
Best answer

There are two phases in the life cycle of a JSP:

  1. Translation and Compilation Phase
  2. Execution Phase

During the translation and compilation phase the container creates a servlet for the JSP from the source file. A JSP page services client requests as a servlet. When a request is mapped to a JSP page, the web container first checks whether the JSP page’s servlet exists and if it exists, whether it is older than the JSP page. If the servlet is older, the web container translates the JSP page into a servlet class and compiles the class. During this phase, the container interprets the scripting elements, directives and actions, and the custom actions referencing tag libraries used in the page.

During the execution phase the JSP container executes the servlet generated from the JSP page. If an instance of the JSP page’s servlet does not exist, the container:

  1. Loads the JSP page’s servlet class
  2. Instantiates an instance of the servlet class
  3. Initializes the servlet instance by calling the jspInit method

The container invokes the _jspService method, passing request and response objects. If the container needs to remove the JSP page’s servlet, it calls the jspDestroy method.

Ninja Answered on 18th September 2018.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.