What is serverlet life cycle?

Showing Answers 1 - 4 of 4 Answers

arun

  • Oct 17th, 2006
 

Servlet life contains three levels1.init() This method is called automatically without any instanace2.service() This method provides srevices for the client requests & responses.3.destory() this method is called by servlet engine itself whenever the client terminates the application.

  Was this answer useful?  Yes

Rajkumar

  • Nov 7th, 2006
 

servlet lifecycle consists of 5 methods but most of the time it concentrates only on three methods .Those methods are init(ServletConfig config) service(ServletRequest req,ServletResponse res) destory()init() method is called before any request is given to service()method.This method takes the ServletConfig object as a parameter.By using this object we can access the parameters which are declared in Deployment File(web.xml).And also we can implement this method to do any intialing the data like getting database connection initialsing the parameters etc.After completeing the init() method webcontainer calls the service()method passing request and response objects as parameters.By using request object we can access the request data(Like form values).By using response object we can generate the response.For every request it creates a new thread and calls the corresponding doXXX()method.This method(i.e service())designed in such a way that depending upon the request method it calls the either doGet() or doPost() method.After completeing the service() method it calls the destory() method.After this method servlet instance is destroyed.In future it may not available for other requests...before calling the destroy() method service () method gives a chance to other threads for execution.This method is also responible for closing any resources like closing database connections etc.The other two methods aregetServletName-->returns the ServletNamegetAServletConfig()-->returns the servletConfig object

  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