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
ServletContextProviderinterface. In order to answer this properly, you need to provide the package whereServletContextProvideris 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
getServletContextLocalmethod on the internet (after a Google search) are either this question, or copies of this question.Assuming
getServletContextProvider()returns aServletContextProviderclass 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,LiferayServletContextProviderdoesn't have thegetServletContextLocal()method, and extends Object.getServletContextLocal()method, nor does theResourceProviderinterface 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 thelocalvariable is a class extendingjavax.portlet.GenericPortlet. ThegetServletContext(local)method would then return thejavax.servlet.ServletContextwhich was associated with said variable. Whether it is the samejavax.servlet.ServletContextas returned bygetServletContext()depends on where theGenericPortletvariable was assigned.Do yourself a favor and cite the location of the tutorial to which you're referring.