Explain Servlet and JSP life cycle

Showing Answers 1 - 19 of 19 Answers

satyanarayana.k

  • Jun 2nd, 2005
 

hi 
 
jsp life cycle has three important methods such as  
init() ->this initalizes the jsp information with the configuration parameters. 
 
service : here the business logic starts. that is, all the request and responses goes here. 
 
destroy() : once the process is completed, it will be killed. 
 
Servlets derived as HttpServlets and GenericServlet 
in HttpServlets have 3 methods. 
init() -> servlets confiration parameters are created and passed. 
doPost(), doGet() : this are the business logic methods. 
 
destroy() : ultimately kills the servlets once the process completed. 
 
Thanks and Rgds 
Satyanarayana 
 
 

joadavis

  • Jun 3rd, 2005
 

This is not a "core Java" question, rather a servlet/jsp question. Webmaster, can you move this question?

  Was this answer useful?  Yes

Sandip

  • Jul 11th, 2005
 

Servlet Lifecycle: 
init() ->this initalizes the servlets initialization information with the configuration parameters.  
 
service : here the business logic starts. that is, all the request and response services goes here.  
 
destroy() : once the process is completed, it will be used to destory all vairables and objects used by servlets.  
 
JSP lifecycle is somewhat diff that servlet life cycle. It includes four steps for the same. 
jspInit:works like servlet init method. 
jspTransleted: used to translate the JSP into servlet and in case of Tomcat server,thats translated servlets goes in work directory. 
_jspService: Its works like servlet's service method. 
jspDestory: same as servlets destory method. 
 
Thanks 

Sangram Keshari Sahu

  • Jul 18th, 2005
 

Heading is Displayed as "Core Java". 
Questions are from Advance Java.

  Was this answer useful?  Yes

Pavan

  • Sep 1st, 2005
 

I'll explain JSP life cycle.Servlet life cycle is already explained nicely. 
JSP life cycle include two important phases. 
1. Translation Phase 
2. Request Processing Phase. 
In 1st phase JSP is translated to Servlet and in 2nd phase requests will be processed by it. Init and Destroy methods are same as Servlets. 
 
Thanks & Regards, 
Pavan Kumar.G

  Was this answer useful?  Yes

parimala

  • Sep 12th, 2005
 

Each time Jsp doesn't undergo 2 phases.For first time it goes to Jsp engine. Servlet.class file is created and sent to Sevlet engine where request is processed.

When request comes for same page again that page is directly handled by servlet engine.

  Was this answer useful?  Yes

Alpa Sekhalia

  • Sep 15th, 2005
 

JSP life cycle include two important phases. 
1. Translation Phase 
2. Request Processing Phase. 
In 1st phase JSP is translated to Servlet and in 2nd phase requests will be processed by it. Init and Destroy methods are same as Servlets. 

  Was this answer useful?  Yes

sarat

  • Sep 29th, 2005
 

hi friends,

the life cycle of the servlet is the init for intialize the servlet variables,it is optional method,then the service() is for  request processing,for every new request the servlet can create new thread for process the request,destroy() for destroy the resources which is handled by servlet b4 servlet instance destroy.

inthe jsp also same but here two phases are translation phase ,request process phase

translation phase converts jsp page to servlet

request process phase process the client requests

  Was this answer useful?  Yes

Devidas Sonawane

  • Nov 8th, 2005
 

First Servlet is loaded means thread created and initialised by using init() method and it communicates with client through service() method and unloaded  servlet and call destroy() method. JSP is first converted into servlet by using servlet engine then use created servlet.

  Was this answer useful?  Yes

jemi

  • Apr 5th, 2006
 

JSP Lifecycle:

Translation Phase: JSP Page will be converted to Servlet.

Compilation Phase: The resulting servlet is compiled.

Instantiate and loading Phase: Instance will be created for the servlet ands it will be loaded to memory.

Call jspinit():Perform Initialization process.

Call _jspService(): this will be called upon each request.

Call jspDestroy(): the instance will be destroyed when not needed any more.

Servlet Life Cycle:

Call init(): servlet will be initialized using web.xml

Call service(): this will be called upon each request which in turn calls doXXX() methods.

call destroy(): called when the servlet object is no longer needed.

First it check that if there are existing JSP is there are not. If it is then it will reload that servlet and send to the respnse to the client requst. If it is not the a servlet will generate and loading executing will done.

  Was this answer useful?  Yes

Life cycles are pretty same, as the JSP will be translated into a servlet during the translation phase, the important point to be considered here is if we include another JSP by making use of static directive include or dynamic include, how the JSP will be translated in to servlet/s. Even though JSP will be converted as a Servlet, it is not advisable to use it as a Controller, but only restricted for View alone in MVC.  

Srinivas Dasamanthula.

  Was this answer useful?  Yes

A Servlet is a Java class which faclitates a web developer to write dynemic web pages. JSP is the presentation componant that used with Servlets to make a page dynamic. Generally a JSP is a HTML document which includes java codings, other tags, java beans etc. The Servlets facilitates with modeling the business logic while the JSP doing the presentation part of a web content.

A servlet has a life cycle trough out its execution withing a servlet container (A web server like Tomcat, Glassfish, JBoss etc.)

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions