jsp life cycle and servlet

JSP Life Cycle

Hi All we are going to see the JSP life cycle.It involves from birth to death of JSP.If we have studied the advance java concepts or you are going to start JSP is most important thing to be understood by every java developer.

So what about the life cycle of JSP.

jsp life cycle and servlet
“A JSP page is converted into Servlet in order to service requests.

Stages in JSP Life Cycle

  1. First when user enters the url of jsp the jsp engine
  2. JSP engine loads the specified JSP compiles the JSP page.
  3. After compilation of JSP page it is converted and made as a Servlet .
  4. This servlet will live in Container servlet container.Servlet container is responsible for maintaining the life cycle means survival of the objects.
  5. Container creates instance of the jsp’s servlet.
  6. Whatever we have defined in the <%!%> is the declaration tag so the declarations done in the jsp goes in the jsp_init() which means when the serlvlet initializes it will be loading all the declared variables.
  7. Also whatever defined inside the <%%> is shifted to the jsp_service() method of the compiled servlet.
  8. jsp_destroy() this is last phase of jsp where jsp unloads.Here the jsp variables and objects are cleaned up (garbage collection takes place as our jsp is no more required.)

In short when ever jsp is compiled it follows the life cycle of servlet afterwords.

To get more details i would love to recommend you book jsp in action to quickly learn jsp.

One thought on “jsp Life Cycle”

Leave a Reply

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