servlet constructor

Discussions

Web tier: servlets, JSP, Web frameworks: servlet constructor

  1. servlet constructor (2 messages)

    hello friends,

      I would like to know the exact reason for why a servlet
    doesnot have a constructor , the reason given in the
    book is not satisfactory.

     thanks in advance

     regards
    - mohan

    Threaded Messages (2)

  2. servlet constructor[ Go to top ]

    A servlet is a container managed object. Since the life cycle is managed, the constructor is not very useful to initialize a servlet. Instead, you use the init() method to do any initialization.

    The difference is that servlet construction and servlet initialization are not the same (object lifecycle vs servlet lifecycle).
  3. servlet constructor[ Go to top ]

    So it is intentional that servlets don't use constructors!!!!I've been trying to get mine to work for months. Now I feel silly. So my next question is can you overload the init() method?