File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Service Method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Service Method" Watch "Service Method" New topic

Service Method

Prabhu Chandrasekaran
Ranch Hand

Joined: Oct 14, 2000
Posts: 36
I have a basic doubt in service method implementation in servlets.
Does the service method in a servlet get executed every time a servlet is called?
Can you give me the life cycle of a servlet which comprises of an init(), service(), doGet(), doPost() and destroy() ?

Advance Thanks...
sandhya Jahagirdar

Joined: Oct 19, 2000
Posts: 2
init will be called once when servlet first time called.
the service() method will invoke every time the request will be made to the servlet and it recognizes the header which has information about the methods to be invoked (put,get,post etc) and then it dispatches to the doXXX methods.
whatever I know I told.
Prabhu Chandrasekaran
Ranch Hand

Joined: Oct 14, 2000
Posts: 36
Hi Sandhya,
Thanks for your reply.
I will post any more doubts that I have in this forum.


Joined: Oct 24, 2000
Posts: 7
here's the servlet life cycle
1) create and initialize the servlet. here it calls the init method only once the servlet is loaded in the memory, i.e when the servlet engine starts.
2) handle zero or more service calls, i.e. handle all the clients calls . every client request creates one thread, the servlet creates one thread for each doget() and dopost() methods.
3) destory the servlet and garbage collect it.
I agree. Here's the link:
subject: Service Method
It's not a secret anymore!