Results 1 to 5 of 5

Thread: What are the methods being used in a servlet to initialize and destroy it?

  1. #1
    Join Date
    Oct 2010
    Posts
    163

    What are the methods being used in a servlet to initialize and destroy it?

    Hello my friends , I have completed my graduation , but since i had opted for web development when I was asked about the electives being taken in my fifth semesters , but now I want to learn he Java language . I had learned HTML and ASP in he web development , but in java there is lot of things to be learned on of my friend who was senior to me had gone for an interview he was asked a lot about the Java and was asked about the methods being asked in the Servlet lifecycle , can any one please tell me what he actually meant by that , I did not get anything from that question , and I am a bit worried what will happen if I appear for any interview and been thrown such questions , if so I will go black and will not clear any of the Java relevant interview.

  2. #2
    Join Date
    Apr 2009
    Posts
    488

    Re: What are the methods being used in a servlet to initialize and destroy it?

    Most of the students who choose web development over java tend to face this issue as they just look at the previous scores and see that students have scored more marks in the web development over java and then opt for it and later on know th importance of the java, nevertheless you had asked about the methods , I can name them they are init method , service method and the last method is destroy method.

  3. #3
    Join Date
    May 2009
    Posts
    529

    Re: What are the methods being used in a servlet to initialize and destroy it?

    The life cycle begins when container creates an object of servlet class and invokes the the init() method, and terminates with the container invoking the destroy() method.
    The syntax of these methods is shown as below of this methods are shown below :

    Following is the syntax of the init method

    Code:
    public void init(ServletConfig con) throws ServletException<br />
    public void service(ServletRequest request , ServletResponse response ) throws ServletException, IOException
    Following is the syntax of the destroy method

    Code:
    public void destroy()

  4. #4
    Join Date
    Apr 2009
    Posts
    569

    Re: What are the methods being used in a servlet to initialize and destroy it?

    The servlet life cycle consists of four steps, instantiation, initialization, handling of a particular request and then that particular is ended .During initial procedure , web container actually loads the servlet class and generates a new object of the servlet. The container can generate a servlet object at container startup or it can holdup it until the servlet is required to service a request. During initialization period of the Servlet life cycle, the web container begins the servlet instance by invoking the init() method. That container passes an instance implementing the ServletConfig interface with the help of the init() function . This configuration instance permits the servlet the right to use name-value initialization arguments from the web application

  5. #5
    Join Date
    May 2009
    Posts
    511

    Re: What are the methods being used in a servlet to initialize and destroy it?

    The servlet saves a message into server log file when servlet is initialized and initializes the counter variable to 0. Each time the service function is invoked , it increases the counter by 1 and shows the present value of counter to user. At last when destroy method is invoked , it stores a message to server log file. Thus a init function initializes , service method does the actual function and the destroy method destroys or terminates the actual instance of the servlet.

Similar Threads

  1. Did I destroy my AMD x3 455
    By ogusta89 in forum Motherboard Processor & RAM
    Replies: 4
    Last Post: 26-12-2010, 10:25 PM
  2. JSP and Servlet problem
    By Devabrata in forum Software Development
    Replies: 5
    Last Post: 21-07-2010, 12:12 AM
  3. What is Servlet container?
    By Sonam Goenka in forum Software Development
    Replies: 5
    Last Post: 05-02-2010, 08:13 AM
  4. How to search destroy desktop
    By DIONISIO in forum Windows Software
    Replies: 3
    Last Post: 29-06-2009, 07:12 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,988,149.56383 seconds with 17 queries