In the tutorials I read I came across getServletContext() but what are these 2 for ?
This is how the line looks:
ServletContext sc = getServletContextProvider().getServletContextLocal();
How is this different from:
ServletContext sc = getServletContext();
Your answer is specific to the class likely implementing a
ServletContextProvider
interface. In order to answer this properly, you need to provide the package whereServletContextProvider
is declared, or even more helpful, the class or interface which contains thegetServletContextProvider()
andgetServletContext()
methods (declared or abstract).Even easier for us, provide a link to the tutorial you reference, or some additional context (no pun intended). The only references to a
getServletContextLocal
method on the internet (after a Google search) are either this question, or copies of this question.Assuming
getServletContextProvider()
returns aServletContextProvider
class or interface, there are several interfaces and classes available with that name; I'll go through each one I found:getServletContextLocal()
method.getServletContextLocal()
method; Implementer of said interface,LiferayServletContextProvider
doesn't have thegetServletContextLocal()
method, and extends Object.getServletContextLocal()
method, nor does theResourceProvider
interface it implements, and it extends Object.getServletContextLocal()
method, nor do the 4 implementing classes listed on that link.getServletContextLocal()
method, and extends Object.getServletContextLocal()
method.Conclusion: What you've typed is likely a typo in the tutorial you read, probably referencing the most common interface available,
org.apache.portals.bridges.common.ServletContextProvider
, which has agetServletContext(GenericPortlet portlet)
method. What the tutorial likely intended to write isgetServletContextProvider().getServletContext(local)
where thelocal
variable is a class extendingjavax.portlet.GenericPortlet
. ThegetServletContext(local)
method would then return thejavax.servlet.ServletContext
which was associated with said variable. Whether it is the samejavax.servlet.ServletContext
as returned bygetServletContext()
depends on where theGenericPortlet
variable was assigned.Do yourself a favor and cite the location of the tutorial to which you're referring.