Why Can't Use constructor instead of init method to initialize servlet



Can we use the constructor, instead of init(), to initialize servlet?


Yes. But you will not get the servlet specific things from constructor. The
original reason for init() was that ancient versions of Java couldn t dynamically
invoke constructors with arguments, so there was no way to give the
 constructor aServletConfig. That no longer applies, but servlet containers still 
will only callyour no-arg constructor. So you won t have access to a 
ServletConfig or ServletContext.


Enter your email address to get our daily JOBS & INTERVIEW FAQ's Straight to your Inbox.

Make sure to activate your subscription by clicking on the activation link sent to your email