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

Can you control when passivation occurs?

591


How are the elements of a borderlayout organized?

589


What is prototype?

597


What are callback interfaces?

585


What is the immediate superclass of the applet class?

590






Explain how will the struts know which action class to call when you submit a form?

515


Which javutil classes and interfaces support event handling?

571


Can we sent objects using Sockets?

637


What is the RMI and Socket?

618


What modifiers may be used with an inner class that is a member of an outer class?

566


How database connectivity in XML is achieved?

1761


Write a program to show synchronization?

681


Explain about thread synchronization inside a monitor?

1989


Which characters may be used as the second character of an identifier, but not as the first character of an identifier?

531


what are the activation groupworks?

1667