Life Cycle of servlets?

Answers were Sorted based on User's Feedback



Life Cycle of servlets?..

Answer / shakir khan

javax.servlet.Servlet interface defines 3 methods known as
life cycle.
Servlet intialisation takesplace every first time,it
receives a request and remains in memory till times out or
server shutdown

When first request came in for a servlet,servlet invoke
init() only once.

public void init(ServletConfig config)
{
}
Thereafter if any user wants requet,it will directly
executes the service().

public void service(ServletRequest req,ServletResponse res)
throws servletException,IOException
{
}
When server wants to remove the servlet from pool ,it will
executes the destroy().

public void destroy()
{
}

Is This Answer Correct ?    14 Yes 2 No

Life Cycle of servlets?..

Answer / prashant

1> Server loads the servlet.
2> Server creats one or more instances of the servlet
3> Server calls the init()method of each Servlet instance
4> Servlet request is received
5> Servlet service()method processes the request
6> Servlet calls the service()method of the servlet instance
7> Servlet service()method then process the request & send
the output to the client
8> Servlet waits until next request is received (if yes
continue from step no-4 )
9> Servlet is unloaded by the server by calling the destroy
()method

Is This Answer Correct ?    5 Yes 0 No

Life Cycle of servlets?..

Answer / 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

Life Cycle of servlets?..

Answer / ravikiran(aptech mumbai)

1).container will find the web.xml
2).container parses the web.xml
3).creates the instance of servlet using
class.forname(classname).newInstance()
4).preinitializes the servlet with the entry known as
<load-on-startup>
5).Initializing the servlet instance using
init(ServletConfig config) method
6).Container creates request and resonse objects and finds
that the requested resource is a servlet and invokes a new
thread for the particular request
7).Calls doGet() or doPost() inaccordance with the method
decared inside html
8).And passes the request and response objects into the
doGet() or doPost()
9).And with the help of response object the response is ent
back to the client
10).destroy() method call will cleanup the resources
11).the thread will go into a pool
12).The request and response objects will be sent to an
output stream

Is This Answer Correct ?    4 Yes 2 No

Post New Answer

More Servlets Interview Questions

Are Servlets Thread Safe? How to achieve thread safety in servlets?

0 Answers  


What are the Internal servlets maintained by the web server?

1 Answers   Infosys,


Difference between forward() method and sendredirect() method ?

0 Answers  


where the session data will stored?

4 Answers  


How long do servlets last?

1 Answers  






Is servlet synchronized?

0 Answers  


Which interface should be implemented by all servlets?

0 Answers  


How do I know if java is running on linux?

0 Answers  


What is the purpose of inter-servlet communication?

0 Answers  


What happens, when client requests for server object, which is not yet loaded into the memory?

2 Answers  


Explain jsessionid?

0 Answers  


What is the difference between context parameter and context attribute?

0 Answers  


Categories