Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

servletcontext

 
Neeraja Neeraj
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can anybody pls let me know the difference between the methods:
1.getServletContext()
2.getServletConfig().getServletContext()
How does the ServletContext returned by these two methods differ?
Thanks
Neeraj
 
Jason Qiu
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can anybody pls let me know the difference between the methods:
1.getServletContext()
2.getServletConfig().getServletContext()
How does the ServletContext returned by these two methods differ?
There is no any difference!
Acctually, they are the same method.
Please note that the GenericServlet implements the ServletConfig interface as well as Servlet interface. And all HttpServlets are children of GenericServlet.
getServletContext() is defined in ServletConfig interface and is implemented in GenericServlet.
So you can use either the getServletContext() of HttpServlet or use the getServletContext() of the ServletConfig.
They are absolutely the same!
 
Andres Bonifacio
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is additional info. Look at the source code of GenericServlet. The method getServletContext() encapsulate calls to getServletConfig().getServletContext()
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic