Java Server Pages (JSP) Life Cycle

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:

  1. Translation
  2. Compilation
  3. Loading
  4. Instantiation
  5. Initialization
  6. RequestProcessing
  7. Destruction

JSP life cycle Java Server Pages (JSP) Life Cycle

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.)

[code language=”java”]
public void jspInit()
{
//code to intialize Servlet instances
}[/code]

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.

[code language=”java”]
void _jspService( HttpServletRequest req, HttpServletResponse res)
{
//code goes here
}[/code]

4) Invokes the jspDestroy() method to destroy the instance of the servlet class. code will look like below –

[code language=”java”]
public void jspDestory()
{
//code to remove the instances of servlet class
}[/code]

Reference: http://beginnersbook.com/2013/05/jsp-tutorial-life-cycle/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值