What are getServletContextLocal() and getServletContextProvider()

82 Views Asked by At

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();
1

There are 1 best solutions below

0
On

Your answer is specific to the class likely implementing a ServletContextProvider interface. In order to answer this properly, you need to provide the package where ServletContextProvider is declared, or even more helpful, the class or interface which contains the getServletContextProvider() and getServletContext() 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 a ServletContextProvider class or interface, there are several interfaces and classes available with that name; I'll go through each one I found:

  1. Interface org.apache.portals.bridges.common.ServletContextProvider does not have a getServletContextLocal() method.
  2. Interface com.liferay.portal.kernal.servlet.ServletContextProvider doesn't have a getServletContextLocal() method; Implementer of said interface, LiferayServletContextProvider doesn't have the getServletContextLocal() method, and extends Object.
  3. Class ca.grimoire.maven.ServletContextProvider doesn't have a getServletContextLocal() method, nor does the ResourceProvider interface it implements, and it extends Object.
  4. Interface org.atmosphere.di.ServletContextProvider does not have a getServletContextLocal() method, nor do the 4 implementing classes listed on that link.
  5. Class com.atlassian.jira.web.ServletContextProvider not have a getServletContextLocal() method, and extends Object.
  6. Abstract Class org.kaleidofoundry.core.web.ServletContextProvider does not have a 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 a getServletContext(GenericPortlet portlet) method. What the tutorial likely intended to write is getServletContextProvider().getServletContext(local) where the local variable is a class extending javax.portlet.GenericPortlet. The getServletContext(local) method would then return the javax.servlet.ServletContext which was associated with said variable. Whether it is the same javax.servlet.ServletContext as returned by getServletContext() depends on where the GenericPortlet variable was assigned.

Do yourself a favor and cite the location of the tutorial to which you're referring.