The life cycle of JSP page is a process of converting JSP page to a servlet or in other words, you can say web container generates a separate file with (_jsp.java) extension. or you can say the complete execution of a JSP page.
Before this have a look at what is JSP.
JSP is Java server page. this technology is used to create dynamic web applications. JSP adds Java code inside HTML using JSP tags. We can do server-side programming using JSP as well as Html for client side. JSP allows us to write HTML code containing tags, inside which we can include powerful Java programs. Using JSP, one can easily separate Presentation and Business logic as a web designer can design and update JSP pages creating the presentation layer.
There is all step witch come in the life cycle of JSP page.
- Translation or convert JSP into Servlet code.
- Compilation of Servlet to bytecode.
- Loading Servlet class.
- Creating servlet instance.
- Initialization by calling jspInit() method.
- Request Processing by calling _jspService() method.
- Destroying by calling jspDestroy() method.
JSP is an extended version of servlet so the life cycle of JSP is also same a servlet lifecycle but difference is only translation face.
We can take an example for this Like I have (hello.jsp) file with following steps.
- web container translate this (hello.jsp) file in (.java) file.
- Compile into java servlet class and generate a bytecode(.class) file.
- Bytecode loaded by the class loader.
- Container creates an instance of that servlet class.
- Now for service request initialized servlet by jspInit().
- Web container call _jspService() method for each request.
- At the end jspDestroy() destroy the request.