what is servlet life cycle?

Answer Posted / rama

The three important functions that implement the life cycle
of servlet are init(),service(),destroy().
When a client/user specifies a request by entering the
URL in the browser the browser generates an HTTP request
for it and sends to the server.
On receiving the HTTP request the server maps a servlet
to this request. the servlet is then dynamically retrieved
and loaded in the memory.
The server now calls the init() method of the servlet.
Parameters can be sent to configure the servlet. This
method is called only once when the servlet is first
loaded.
When a request arrives for this servlet the server
invokes the service() method. this is the method which
handles all the HTTP requests and formulates HTTP response.
For every request service() method is called.
When the server decides to unload the servlet it calls
the destroy() method. Any resources which were used by the
servlet or any open files or any database connections can
be restored so that the memory used by these objects and
the servlet can then be garbage collected.

Is This Answer Correct ?    15 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Difference between java beans & servlets?

583


Hello, My project requirement is like I need to create a web page using MVC pattern. I hava a bean class, jsp page, servlet, service and dao. My jsp has two fields. One is dropdown list. The option values has to get populated from the database table. The other one is a text box and its value has to come from database table. As of now I have defined the fields in bean class, got the values from database using arraylists in dao class and I called this from service class. Can anyone please tell me the workflow of how the servlet will get this arraylist and populate the arraylist values as dropdown options in jsp page? Also I would like to know the role of bean class in MVC pattern? Thanks in advance!

1823


What are the kinds of http requests?

600


What are different Authentication options available in Servlets.

561


What is the difference between Servlet Request and Servlet Context when calling a Request Dispatcher?

595






What is the use of servlet wrapper classes?

658


What's the advantages using servlets than using cgi?

547


What is Request Dispatcher?

788


Is tomcat a servlet container?

564


What do you mean by annotations in servlet?

576


What does the term localization refer to?

577


What exception should be thrown when servlet is not properly initialized?

549


What is the difference between forward () and sendredirect () functions in servlet? Explain

539


What is the purpose of requestdispatcher interface?

605


Is servlet synchronized?

595