GenericServlet implements ServletConfig interface which means all the interface functions can be invoked from init() function of GenericServlet. Given this context, why does the Servlet container sends ServletConfig object to init() method? I would also like to know if the ServletConfig object that is passed to GenericServlet.init(ServletConfig) different from GenericServlet object.
I know that GenericServlet is abstract but the above questions also apply to HTTPServlet.
GenericServlet adds the convenience method init() with no ServletConfig - if you only implement that, the init(ServletConfig ) method in GenericServlet will be called and it will call your init(). See the javax.servlet.GenericServlet JavaDocs.
Joined: Sep 17, 2011
Bear Bibeault wrote:By "version" he meant instance.
Thank you Bear. I also learnt that GenericServlet implements ServletConfig interface methods by delegating to ServletConfig object passed by Servlet Container. That means getServletConfig().getInitParameterNames() is the same as getInitParameterNames().
I also got to know that originally GenericServlet didn't implement ServletConfig but later it started implementing for convenience. Do you know why?