Difference between jsp and servlet life cycles

What is the difference between jsp and servlet life cycles?

Servlet's life cycle comprises of the following steps:

a. servlet object is created.
b. init() method initializes the servlet using Servlet Config object as its argument.
c. service() method accomplishes all the work.
d. destroy() method ends the life of servlet.

In JSP's life cycle, after a jsp is translated into a servlet, it behaves in the same way as a servlet.
Thus, at first a ‘.jsp’ is converted into a ‘.class’ i.e. a servlet and the Servlet Life Cycle Steps are followed.

What is the difference between JSP and Servlet life cycles?

In servlet life cycle, the servlet object is created first. The init() method is invoked by the servlet container and the servlet is initialized by its arguments. Servlet’s service() method is invoked next. And at the end, the destroy() method is invoked.

In case of a Java Server Page life cycle, the .jsp is converted into .class file which is a servlet and then follow the process of the servlet. In orther words, the .jsp is translated into servlet and the functionality is same as that of the servlet.
JSP Scripting Elements - Explain JSP Scripting Elements
JSP Scripting Elements - There are three forms of JSP scripting elements that let you insert Java code into the servlet...
Difference between JSP include directive and JSP include action.
JSP include directive - When a JSP include directive is used, the included file's code is added into the added JSP page at page translation time...
JSP Declaration - What is a Declaration?
JSP Declaration - A declaration consists of one or more variables or methods that are used in JSP source file....
Post your comment