Explain the life cycle of servlet?

Answer Posted / surajkumar.java

1. The servlet is controlled by the container in which the
servlet has been deployed. When a request is made to a
servlet, its mapping is searched in web.xml. If mapping
found then the web container loads the servlet class and
creates an instance of it and initializes (e.g servlet
context parameters, database connections objects etc) the
servlet instance by calling the init method.
2. Then invokes the service method, passing a request and
response object. The service provided by a servlet is
implemented in the service method of a GenericServlet and
the doMethod methods (where Method can take the value like
Get, Delete, Options, Post, Put, Trace) of an
HttpServlet. Basically a service method extract information
from the request, access external resources, and then
populate the response based on that information.
3. The container calls destroy method to remove servlet
instance. We also do some specialized handling like closing
a connection, freeing the memory used by local variables etc
by explicitly defining the destroy method inside a servlet
class.

Is This Answer Correct ?    14 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

we use MainFrame and using os390 for operating system with DB2 data base in IRAN and interest programing with java and use webspere for world wide,please help me where i should start?

1930


Explain what is synchronization?

577


What is chat area? Explain.

560


What is the map interface?

616


Do I have to use jsps with my application?

585






What is JTS?

1864


A user of a web application sees a jsessionid argument in the URL whenever a resource is accessed. What does this mean? a. The form must have the field jsessionid b. URL rewriting is used as the session method c. Cookies are used for managing sessions

1815


Can I run seam with jdk 1.4 and earlier?

561


Why does the option tag render selected=selected instead of just selected?

680


Are enterprise beans allowed to use thread.sleep()?

652


Write a singleton program?

574


What is RMI and what are the services in RMI?

613


What value does read() return when it has reached the end of a file?

556


What do you mean by Socket Programming?

551


In inglish: How to convert jar to exe files? Em português: Como converter arquivos .jar para .exe?

2158