Life Cycle of servlets?

Answer Posted / bhavani

webcontainer loads the servlet from web application after
that container invokes public void init() method.the
purpose of init( ) function is some parametera are
requried to instantiate servlet class instance variables(
the parameters are driverclass,url,pass etc) these
variables are called as initialization parameters.

to pass the parameters into public void init( ) method
developer must pass all these parameters from web.xml file.

container reads all the parameters from web.xml file
stroes into one hash kind of object called ServletConfig .
in init() method we must receive config object reads
velues from it and instantiate connection object.

if developer want to change driver parameters,then he/she
need not have to change those parameters in servlet class
instead he called modify it in web.xml file
after init() method container invokes one function on
servlet class instance called
public void service(ServletRequest req,ServletResponse res)
throws servletException,IOException
{
} client request is processed in this method
like this web creates new instance of each servlet during
first client visit to servlet.
from next request on words web container remains the same
instance and directly sends client request to service()
method.
public void destroy()
this method is used database connection want to be closed.

Is This Answer Correct ?    3 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is servlet looping or chaining?

897


What’s the difference between forward() and sendredirect() methods?

772


Explain the difference between servletconfig and servletcontext in servlet?

765


What is pure servlet?

897


What is http servlet?

783


What is a servlet engine?

737


What is the disadvantage of cookies?

765


Differentiate between the web server and application server?

758


What do you mean by scope object and what are its types?

771


What is load-on-startup in servlet?

794


How do you run a servlet?

771


What are some disadvantages of storing session state in cookies?

786


How many objects of a servlet is created?

994


What is meant by servlet? What are the parameters of the service method?

790


What is meant by session? Tell me something about httpsession class?

780