We can divide the whole life cycle into following phases-
1.Translation of JSP to Servlet code
In this phase,a java servlet file is created for the source jsp file.
Syntax and tag files are checked before translation.
2.Compilation of Servlet to bytecode.
The generated servlet file is compiled to its java class file.
3.Loading Servlet class.
the container loads the JSP page’s servlet class.
4.Creating servlet instance
the container instantiates an instance of the servlet class.
5.Initialization by calling jspInit() method
jspInit() method is called immediately after the instance was created.
It is called only once during JSP life cycle.
jspInit() method can be overridden to initialize resources like database and network related connections.
6.Request Processing by calling _jspService() method
This method is called for each request coming for this jsp.
It has request and response objects as arguments.
It can not be overridden.
The underscope sign before jspService is for indicating
that it can not be override.
jspInit and jspDestroy both methods can be overridden.
7.Destroying by calling jspDestroy() method
This is called when servlet is destroyed.
When the Container removes the servlet instance from service, it calls this method to perform any required clean up.
It is called only once during JSP life cycle.
jspInit(), _jspService() and jspDestroy() are called the life cycle methods of the JSP.
The following diargram is just pictorial representation of what we learnt till now.
- Translation
- Compilation
- Loading
- Creating Instance
- Initialization
- Request Processing
- Destroy
1.Translation of JSP to Servlet code
In this phase,a java servlet file is created for the source jsp file.
Syntax and tag files are checked before translation.
2.Compilation of Servlet to bytecode.
The generated servlet file is compiled to its java class file.
3.Loading Servlet class.
the container loads the JSP page’s servlet class.
4.Creating servlet instance
the container instantiates an instance of the servlet class.
5.Initialization by calling jspInit() method
jspInit() method is called immediately after the instance was created.
It is called only once during JSP life cycle.
jspInit() method can be overridden to initialize resources like database and network related connections.
6.Request Processing by calling _jspService() method
This method is called for each request coming for this jsp.
It has request and response objects as arguments.
It can not be overridden.
The underscope sign before jspService is for indicating
that it can not be override.
jspInit and jspDestroy both methods can be overridden.
7.Destroying by calling jspDestroy() method
This is called when servlet is destroyed.
When the Container removes the servlet instance from service, it calls this method to perform any required clean up.
It is called only once during JSP life cycle.
jspInit(), _jspService() and jspDestroy() are called the life cycle methods of the JSP.
The following diargram is just pictorial representation of what we learnt till now.
![]() |
JSP Page Life Cycle |