Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • 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 does GenericServlet implement ServletConfig

 
Ranch Hand
Posts: 209
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I am just a bit confused with the following class structure.

Why does javax.servlet.GenericServlet implement javax.servlet.ServletConfig? It IS a servlet, not a servlet configuration. Seems like competely different responsibilities being assigned to one class.

Eg, it makes sense to have Employee class implement Person and Administrator interfaces (employee is a person, and has a role of administrator). But it does not make sense for the Employee class to implement EmployeeAddress interface.

In addition, GenericServlet inherits a Servlet#getServletConfig() method, which complicates the picture even more.

Would not the following piece of code get servlet config:


Why would one ever use GenericServlet#getServletConfig()? Does not it just return a reference to itself?

I'd say that the most appropriate relationship between servlet and servlet configuration should be *HAS*; servlet HAS a servlet configuration, then GenericServlet#getServletConfig() would make sense.

I'd greatly appreciate your thoughts on this matter.


[ October 24, 2004: Message edited by: Alex Sharkoff ]
 
Ranch Hand
Posts: 1258
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ironically, only hippies (kidding) use GenericServlet (for what, who knows). HttpServlet, however, does not implement ServletConfig. I haven't yet met a person, even a hippy, who has used GenericServlet -- anybody?
 
Alex Sharkoff
Ranch Hand
Posts: 209
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've not met any admirers of GenericServlet either, everyone is only after HttpServlet beauties

HttpServlet extends GenericServlet, and therefore implicitly implements ServletConfig.


 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Exactly ...
Since HTTPServlet extends the GenericServlet, and therefore implicitly implements ServletConfig.
Hence, the piece of code mentioned :




is a valid way of getting the servletConfig.

Another question would be, when a servlet is initialized, why do the container call the init(ServletConfig) method of HttpServlet, passing the servletConfig. The various configuration parameters should be available to the servlet automatically (since it has implemented the servletConfig.)

Can anybody clear the mud...
:roll:
 
Now I am super curious what sports would be like if we allowed drugs and tiny ads.
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic