Balaji Vankadaru wrote:We cannot write constructors with arguments in a servlet class. It will throw Exception.
Not really correct. A servlet can have any number of constructors, but if it has constructors with arguments then you must add a default constructor without arguments, because the compiler will not insert it for you. Only the default constructcor will ever be called, all others are dead weight.
If you do not intend to access servlet context and config its possible to manage your code trough constructor.
Not really correct, either. A servlet's constructor will only be called once, whereas the
init and
destroy methods can be called multiple times.
Simple rule of thumb: never put a constructor in a servlet.