servlet life cycle

Posted on 2006-04-27
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
Question by:stmani2005
    LVL 5

    Expert Comment

    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

    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.
    LVL 3

    Accepted Solution

    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.    
    LVL 8

    Author Comment

    what is the use of post method

    difference between service and post method
    LVL 5

    Expert Comment

    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

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    I had a project requirement for a displaying a user workbench .This workbench would consist multiple data grids .In each grid the user will be able to see a large number of data. These data grids should allow the user to 1. Sort 2. Export the …
    Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
    Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
    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.

    729 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

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now