Generally Servlets don’t have the Constructor, because a servlet is just like an applet in the respect that it has an init() method that acts as a constructor, an initialization code you need to run should be place in the init(), since it get called when the servlet is first loaded.
You cann’t use a Constructor instead of init() method to initialize a servlet.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 a ServletConfig. That no longer applies, but servlet containers still will only call your no-arg constructor. So you won’t have access to a ServletConfig or ServletContext.
Even while you trying to override the init() method you should pass the argument a ServletContext object because the container passes the ServletConfig object to the servlet only when it calls the init method. So ServletConfig will not be accessible in the constructor.
Even while you trying to override the init() method you should pass the argument a ServletContext object because the container passes the ServletConfig object to the servlet only when it calls the init method. So ServletConfig will not be accessible in the constructor.