servlet life cycle

Could you explain servlet life with simple words

i dont want link.

what is the need for public void init method
Manikandan ThiagarajanSenior consultantAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Servlet class is first loaded by the class loader then it is initialized by calling init() method and then it will process requests mapped to it and finally it destroys itself by calling destroy() method and get garbage collected.
the init method is called by the servlet container to indicate to a servlet that the servlet is being placed into service.
This way you can do some initializations at the time when your servlet becomes active and available.
Hi This might help you remember better!!

In anology way it is your own life
                                             Being Born -      Grow -              Do some work  --      die

In short Servlet life cycle in        (Loads, Creates ), Initializes , offers Services--   Destroy.

The life cycle of a servlet is controlled by the Web  container

When a request is mapped to a servlet, the Web  container performs the following steps.

                If an instance of the servlet does not exist, the Web container
                                                                         Loads the servlet class.
                Then Creates an instance of the servlet class.

               Then Initializes the servlet instance by calling the init method.

                Invokes the service method, passing a request and response object.
                If the container needs to remove the servlet, it finalizes the servlet by calling
                                                                          the servlet's destroy method.    

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Manikandan ThiagarajanSenior consultantAuthor Commented:
what is the use of post method

difference between service and post method
Service method is provided in GenericServlet for handling all sorts of requests like http ftp, etc.
But if you want to handle only Http requests you need to subclass the HttpServlet having Http specific methods as doGet(), doPost(), doHead() etc for handling GET, POST, and HEAD request respectively.
The difference between GET and POST method is that with GET method , the query string is simply appended to the URL of the program when the client issues the request to the server where as with POST method , the data is sent as standard input along with the request body.
In HttpServlet, service() method simply calls the Http specific method depecnding upon the type of request.
For more refer:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java EE

From novice to tech pro — start learning today.