JSP Life Cycle
A JSP page life cycle is defined as a process from its translation phase to the destruction phase.
The life cycle of a jsp page comprises of following phases
- Translation phase
- Compilation phase
- Initialization phase
- Execution phase
- Destruction phase
1. Translation phase
In this phase, JSP Servlet engine (web container) converts the jsp page into a servlet. This is known as translation (translation of jsp into servlet) phase.
2. Compilation phase
In this phase, translated servlet (.java file) is compiled into its .class file.
3. Initialization phase
In initialization phase, following things happen.
- Web container loads the servlet class
- Creates an instance of servlet
- Class jspinit() method for initialization of the servlet instance
This is done just once in jsp life cycle. Usually, database connection, file opening, creating lookup tables etc tasks are done in initialization phase
4. Execution phase
In this phase, all JSP interactions and logic executions happen for all the requests. As the requested JSP page is loaded and initiated, the JSP engine has to invoke the _jspService() method.
5. Destruction phase
jspDestroy() method is called just before destroying the jsp. All kinds of cleanup code are written inside jspDestroy() method.