• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

two ways to get ServletContext ?

 
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have seen two ways to getServletContext....
1. HttpServlet.getServletContext() which inturn gets from ServletConfig.

2. HttpServlet.getServletConfig().getServletContext()
Any preference ?
Not sure why we have two methods.......
- satya
[ March 03, 2002: Message edited by: Madhav Lakkapragada ]
 
Chicken Farmer ()
Posts: 1932
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
According to the API for the getServletContext() in GenericServlet (which HttpServlet inherits from):


This method is supplied for convenience. It gets the context from the servlet's ServletConfig object.


Apparently it is there just to make our lives easier
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I hate when there are two ways of doing something...call me a pessimist, but I believe that during the course of time, one of these will get into the wrong hands and will evelove into something different....
The wrong attitude:
What the hell man, I can change this, if someone wants let them call the other method. I mean they can always use the other method, its not like I am preventing them. Changing this method is much easier than creating a whole new method.......
- satya
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
GenericServlet implements ServletConfig, so HttpServlet should have getServletContext()
John
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic