JSP pages are saved with .jsp extension which lets the server know that this is a JSP page and needs to go through JSP life cycle stages.
In my previous post about JSP introduction, I explained that JSP is not processed as such, they first gets converted into Servelts and then the corresponding servlet gets processed by Server.
When client makes a request to Server, it first goes to container. Then container checks whether the servlet class is older than jsp page( To ensure that the JSP file got modified). If this is the case then container does the translation again (converts JSP to Servlet) otherwise it skips the translation phase (i.e. if JSP webpage is not modified then it doesn’t do the translation to improve the performance as this phase takes time and to repeat this step every time is not time feasible)
The steps in the life cycle of jsp page are:
Let see the Life cycle of JSP in more detail –
1) As stated above whenever container receives request from client, it does translation only when servlet class is older than JSP page otherwsie it skips this phase (reason I explained above).
2) Then the container –
- compiles the corresponding servlet program
- Loads the corresponding servlet class
- Instantiates the servlet class
- Calls the jspInit() method to initialize the servlet instance( Jsp container will do this job only when the instance of servlet file is not running or if it is older than the jsp file.)
public void jspInit()
//code to intialize Servlet instances
3) A new thread is then gets created, which invokes the_jspService() method, with a request (HttpServletRequest) and response (HttpServletRespnse) objects as parameters -shown below.
void _jspService( HttpServletRequest req, HttpServletResponse res)
//code goes here
4) Invokes the jspDestroy() method to destroy the instance of the servlet class. code will look like below –
public void jspDestory()
//code to remove the instances of servlet class