Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Of the defined EventListener interfaces in the Servlet API, the javax.servlet.ServletContextListener events are actually not support. For one thing they do not make much sense in an OSGi environment. On the other hand they are hard to capture and propagate. For example in a bridged environment the contextInitialized event may be sent before the framework and any of the contained bundles are actually ready to act. Likewise the contextDestroyed event may come to late.

Servlet Context Notes

ServletContext instances are managed internally by the Http Service implementation. For each HttpContext instance used to register one or more servlets and/or resources a corresponding ServletContext instance is created. These ServletContext instances is partly based on the single ServletContext instance received from the Servlet Container — either embedded Jetty or some external Servlet Container when using the Http Service Bridge — and partly based on the provided HttpContext instance:

Method(s)

Based on ...

getContextPath, getContext, getMajorVersion, getMinorVersion, getServerInfo

Servlet Containers ServletContext

getResourcePaths

Bundle.getEntryPaths of the bundle using the Http Service

getResource, getResourceAsStream

HttpContext.getResource

getMimeType

HttpContext.getMimeType

getRequestDispatcher, getNamedDispatcher, getInitParameter, getServlet, getRealPath

Always return null

getInitParameterNames, getServlets, getServletNames

Always returns empty Enumeration

getAttribute, getAttributeNames, setAttribute, removeAttribute

By default maintained for each ServletContext managed by the Http Service. If the org.apache.felix.http.shared_servlet_context_attributes framework property is set to true these methods are actually based on the ServletContext provided by the servlet container and thus attributes are shared amongst all ServlectContext instances, incl. the ServletContext provided by the servlet container

Examples

A set of simple examples illustrating the various features are available.

...