This week's giveaway is in the Testing forum.
We're giving away four copies of TDD for a Shopping Website LiveProject and have Steven Solomon on-line!
See this thread for details.
Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Why GenericServlet implements ServletConfig?

 
Ranch Hand
Posts: 355
Redhat Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I didn't understand the exact reason why GenericServlet implements ServletConfig. A servlet will receive its configuration object through init(ServletConfig) which is called by the container itself. This object will stay with the servlet till it dies. So, what's the point in implementing ServletConfig? Doesn't this look odd: a servlet is a ServletConfig ?
 
Ranch Hand
Posts: 924
1
Netbeans IDE Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
every servlet can have a configuration object. when we say class Ball implements Bounceable, we can think this as that a ball has the property of bouncing. it can bounce. extending the analogy to GenericServlet implements ServletConfig we can say that a generic servlet has a configuration stuff associated with it, which is very much reasonable.
 
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ServletConfig is an Interface, can't be instantiated.
GenericServlet and HttpServlet implements ServletConfig, So they have to give implementation to the abstract methods of it.

init(ServletConfig) and init() methods are two initialization methods.

If you think that with init(ServletConfig) method; Servlet get the Object of ServletConfig through Servlet Container, then Have you think how the Container create that Object? (Maybe ServletConfig sc = new GenericServlet(); OR new HttpServlet();)

Also, think about if you can initialize servlet with init(), then Servlet can also able to get ServletConfig object through getServletConfig() method (How it will get that Object?).
 
gurpeet singh
Ranch Hand
Posts: 924
1
Netbeans IDE Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Gaurangkumar Khalasi wrote:ServletConfig is an Interface, can't be instantiated.
GenericServlet and HttpServlet implements ServletConfig, So they have to give implementation to the abstract methods of it.

init(ServletConfig) and init() methods are two initialization methods.

If you think that with init(ServletConfig) method; Servlet get the Object of ServletConfig through Servlet Container, then Have you think how the Container create that Object? (Maybe ServletConfig sc = new GenericServlet(); OR new HttpServlet();)

Also, think about if you can initialize servlet with init(), then Servlet can also able to get ServletConfig object through getServletConfig() method (How it will get that Object?).



you cannod do ServletConfig sc = new GenericServlet() as well as new HttpServlet(); since both GenericServlet and HttpServlet are abstract classes.
 
Gaurangkumar Khalasi
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

gurpeet singh wrote:you cannod do ServletConfig sc = new GenericServlet() as well as new HttpServlet(); since both GenericServlet and HttpServlet are abstract classes.


Maybe with anonymous inner class definition of those abstract classes!!...
 
gurpeet singh
Ranch Hand
Posts: 924
1
Netbeans IDE Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Gaurangkumar Khalasi wrote:

gurpeet singh wrote:you cannod do ServletConfig sc = new GenericServlet() as well as new HttpServlet(); since both GenericServlet and HttpServlet are abstract classes.


Maybe with anonymous inner class definition of those abstract classes!!...



for that correct syntax would have been ServletConfig sc = new GenericServlet(){ }; and not ServletConfig sc = new GenericServlet();

but i think we are deviating from the original topic , which is as to WHY generic servlet implements ServletConfig. the clever answer would be thats how the spec implementors thought of GenericServlet class which abstracts Servlet Functionality
 
Switching from electric heat to a rocket mass heater reduces your carbon footprint as much as parking 7 cars. Tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic