Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

two ways to get ServletContext ?

 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • 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 ]
 
jason adam
Chicken Farmer ()
Ranch Hand
Posts: 1932
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
John Dahlstrom
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
GenericServlet implements ServletConfig, so HttpServlet should have getServletContext()
John
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic