• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Why is ServletConfig obj passed to init() of GenericServlet when the class implements the interface?

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

Regards,
Ravi
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That is the only way the new servlet instance can get the correct version of the object which the server actually uses.

Bill
 
Rajkumar Masanaiyan
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

William Brogden wrote:That is the only way the new servlet instance can get the correct version of the object which the server actually uses.

Bill



Bill: Would you please explain how GenericServlet gets the object version? Would you also explain how this object version is important to Servlet lifecycle?

--Ravi
 
Sheriff
Posts: 67752
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
By "version" he meant instance.
 
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As Bear said, I should have used "instance" - as in the reference to the instance of ServletConfig passed in the

javax.servlet.Servlet init(ServletConfig s) method.

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.

Bill
 
Rajkumar Masanaiyan
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?

 
Seriously? That's what you're going with? I prefer this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic