Technically you can define constructors in servlet. But, the declared constructor cannot access the ServletConfig object or throw a ServletException.
Then why is it not customary to declare a constructor in a servlet? Because the init() method is used to perform servlet initialization. In JDK 1.0 (servlet were written in this version), constructors for dynamically loaded Java classes such as servlets cannot accept arguments. Therefore init() was used to initialize by passing the implemented object of ServletConfig interface and other needed parameters.
Also, Java constructors cannot be declared in interfaces. So, javax.servlet.Servlet interface cannot have a constructor that accepts a ServletConfig parameter. To overcome this, init() method is used for initialization instead of declaring a constructor.



















this information is very usefull, thanks u so much . keep posting nice infomation.
Anonymous on July 19th, 2010 10:16 amReally thanks for providing such an useful information…
Anil R. Chinchawade on August 4th, 2010 6:40 pmNice Information.
Ravi on August 18th, 2010 5:15 amthank u very much for providing use full Q&A’s.
accessor on May 16th, 2011 3:14 pmSuperb
Nagraj on October 3rd, 2011 1:30 pmthank you for providing the detailed information.
swami on January 29th, 2012 7:16 amk.L N SWAMI
kswami53@gmail.com