Web tier: servlets, JSP, Web frameworks: why servlet has init method

  1. why servlet has init method (3 messages)

    why servlet has init method it cannot have constructor instead

    Threaded Messages (3)

  2. why servlet has init method[ Go to top ]

    Because the init() method has access to the ServletConfig and the ServletContext. The constructor does not.
  3. to get configuration info......[ Go to top ]

    Hai Naresh,
        A Servlet my need to know about the context and its configuration information about it self in some situations.
       It canbe done when the servlet gets initiated. After the Servlet gets initiated, immidiatly the init(ServletConfig ) methode will be executed to make the knowledge of the configuration information for that servlet.

       Since the ServletConfig is not available until the servlet gets initiated it is then called by the container (after the servlet get instantiated) through init(ServletConfig ) methode from where we can use the configuration information of the servlet. And the init() methode will be called only once for a servlet.


  4. to get configuration info......[ Go to top ]

    N.Naresh Kumar