servlet life cycle

Posted on 2006-04-27
Medium Priority
Last Modified: 2013-11-24
Could you explain servlet life with simple words

i dont want link.

what is the need for public void init method

Expert Comment

ID: 16551050
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.
LVL 11

Expert Comment

ID: 16551062
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.

Accepted Solution

Kanti earned 200 total points
ID: 16551153
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.    

Author Comment

by:Manikandan Thiagarajan
ID: 16583460
what is the use of post method

difference between service and post method

Expert Comment

ID: 16583548
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:

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
A solution for Fortify Path Manipulation.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses
Course of the Month16 days, 11 hours left to enroll

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question