Author | Message |
---|---|
cbort
Posts: 95
|
Posted 07:48 May 04, 2011 |
What is the difference between request.getServletContext() and getServletContext()? |
mbuisin
Posts: 16
|
Posted 09:03 May 04, 2011 |
They should be the same since getServletContext is an interface method inherited from top level interface ServletConfig. The implementation may be different but they all just return a reference to the ServletContext object in Servlet Config. But to answer your question: request.getServletContext() is called from the HTTPServletRequest object while the getServletContext() is inherited from HTTPServlet object |
abajpai
Posts: 52
|
Posted 10:57 May 04, 2011 |
I don't think the HttpServletRequest object lets you access the ServletContext. I couldn't find such a method in the HttpServletRequest api. And that would sort of kill the difference between request scope and session scope wouldn't it?. As for the general getServletContext method which is invoked to get/set objects, I believe that is a part of the HttpServlet Interface which is imported by your servlets. Last edited by abajpai at
11:06 May 04, 2011.
|
mbuisin
Posts: 16
|
Posted 11:05 May 04, 2011 |
I looked it up and it's not explicitly described in the API, but it's listed as one of the inherited methods from ServletRequest. I guess they just didn't bother to put the description again if it's already been defined from a super class. |