This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes servletcontext Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "servletcontext" Watch "servletcontext" New topic
Author

servletcontext

Neeraja Neeraj
Greenhorn

Joined: May 11, 2003
Posts: 29
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

Joined: May 20, 2003
Posts: 13
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

Joined: May 16, 2003
Posts: 19
This is additional info. Look at the source code of GenericServlet. The method getServletContext() encapsulate calls to getServletConfig().getServletContext()


<a href="http://weblog.homelinux.com/blojsom/blog/" target="_blank" rel="nofollow">http://weblog.homelinux.com/blojsom/blog/</a>
 
jQuery in Action, 3rd edition
 
subject: servletcontext
 
It's not a secret anymore!