org.eclipse.jetty.servlet

## Class ServletContextHandler

- java.lang.Object
- - org.eclipse.jetty.util.component.AbstractLifeCycle
  - - org.eclipse.jetty.util.component.AggregateLifeCycle
    - - org.eclipse.jetty.server.handler.AbstractHandler
      - - org.eclipse.jetty.server.handler.AbstractHandlerContainer
        - - org.eclipse.jetty.server.handler.HandlerWrapper
          - - org.eclipse.jetty.server.handler.ScopedHandler
            - - org.eclipse.jetty.server.handler.ContextHandler
              - - org.eclipse.jetty.servlet.ServletContextHandler

- All Implemented Interfaces:
    Handler, HandlerContainer, Server.Graceful, Attributes, Destroyable, Dumpable, LifeCycle
  Direct Known Subclasses:
    WebAppContext

      public class ServletContextHandler
      extends ContextHandler

  Servlet Context. This extension to the ContextHandler allows for simple construction of a context with ServletHandler and optionally session and security handlers, et.

         new ServletContext("/context",Context.SESSIONS|Context.NO_SECURITY);

  This class should have been called ServletContext, but this would have cause confusion with `ServletContext`.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `class` | `ServletContextHandler.Context`
    `static interface` | `ServletContextHandler.Decorator` Interface to decorate loaded classes.

    - ### Nested classes/interfaces inherited from class org.eclipse.jetty.server.handler.ContextHandler

      `ContextHandler.AliasCheck, ContextHandler.ApproveNonExistentDirectoryAliases, ContextHandler.ApprovePathPrefixAliases, ContextHandler.ApproveSameSuffixAliases`

    - ### Nested classes/interfaces inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle

      `AbstractLifeCycle.AbstractLifeCycleListener`

    - ### Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.LifeCycle

      `LifeCycle.Listener`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected List<ServletContextHandler.Decorator>` | `_decorators`
    `protected Class<? extends SecurityHandler>` | `_defaultSecurityHandlerClass`
    `protected int` | `_options`
    `protected Object` | `_restrictedContextListeners`
    `protected SecurityHandler` | `_securityHandler`
    `protected ServletHandler` | `_servletHandler`
    `protected SessionHandler` | `_sessionHandler`
    `protected HandlerWrapper` | `_wrapper`
    `static int` | `NO_SECURITY`
    `static int` | `NO_SESSIONS`
    `static int` | `SECURITY`
    `static int` | `SESSIONS`

    - ### Fields inherited from class org.eclipse.jetty.server.handler.ContextHandler

      `_scontext, MANAGED_ATTRIBUTES`

    - ### Fields inherited from class org.eclipse.jetty.server.handler.ScopedHandler

      `_nextScope, _outerScope`

    - ### Fields inherited from class org.eclipse.jetty.server.handler.HandlerWrapper

      `_handler`

    - ### Fields inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle

      `_listeners, FAILED, RUNNING, STARTED, STARTING, STOPPED, STOPPING`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ServletContextHandler()`
    `ServletContextHandler(HandlerContainer parent, SessionHandler sessionHandler, SecurityHandler securityHandler, ServletHandler servletHandler, ErrorHandler errorHandler)`
    `ServletContextHandler(HandlerContainer parent, String contextPath)`
    `ServletContextHandler(HandlerContainer parent, String contextPath, boolean sessions, boolean security)`
    `ServletContextHandler(HandlerContainer parent, String contextPath, int options)`
    `ServletContextHandler(HandlerContainer parent, String contextPath, SessionHandler sessionHandler, SecurityHandler securityHandler, ServletHandler servletHandler, ErrorHandler errorHandler)`
    `ServletContextHandler(int options)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addDecorator(ServletContextHandler.Decorator decorator)`
    `FilterHolder` | `addFilter(Class<? extends javax.servlet.Filter> filterClass, String pathSpec, EnumSet<DispatcherType> dispatches)` convenience method to add a filter
    `FilterHolder` | `addFilter(Class<? extends javax.servlet.Filter> filterClass, String pathSpec, int dispatches)` convenience method to add a filter
    `void` | `addFilter(FilterHolder holder, String pathSpec, EnumSet<DispatcherType> dispatches)` conveniance method to add a filter
    `void` | `addFilter(FilterHolder holder, String pathSpec, int dispatches)` conveniance method to add a filter
    `FilterHolder` | `addFilter(String filterClass, String pathSpec, EnumSet<DispatcherType> dispatches)` convenience method to add a filter
    `FilterHolder` | `addFilter(String filterClass, String pathSpec, int dispatches)` convenience method to add a filter
    `ServletHolder` | `addServlet(Class<? extends javax.servlet.Servlet> servlet, String pathSpec)` conveniance method to add a servlet.
    `void` | `addServlet(ServletHolder servlet, String pathSpec)` conveniance method to add a servlet.
    `ServletHolder` | `addServlet(String className, String pathSpec)` conveniance method to add a servlet.
    `void` | `callContextDestroyed(javax.servlet.ServletContextListener l, javax.servlet.ServletContextEvent e)`
    `void` | `callContextInitialized(javax.servlet.ServletContextListener l, javax.servlet.ServletContextEvent e)`
    `protected void` | `doStop()` Stop the joined lifecycle beans in the reverse order they were added.
    `List<ServletContextHandler.Decorator>` | `getDecorators()`
    `Class<? extends SecurityHandler>` | `getDefaultSecurityHandlerClass()` Get the defaultSecurityHandlerClass.
    `SecurityHandler` | `getSecurityHandler()`
    `ServletHandler` | `getServletHandler()`
    `SessionHandler` | `getSessionHandler()`
    `protected SecurityHandler` | `newSecurityHandler()`
    `protected ServletHandler` | `newServletHandler()`
    `protected SessionHandler` | `newSessionHandler()`
    `void` | `setDecorators(List<ServletContextHandler.Decorator> decorators)`
    `void` | `setDefaultSecurityHandlerClass(Class<? extends SecurityHandler> defaultSecurityHandlerClass)` Set the defaultSecurityHandlerClass.
    `void` | `setSecurityHandler(SecurityHandler securityHandler)`
    `void` | `setServletHandler(ServletHandler servletHandler)`
    `void` | `setSessionHandler(SessionHandler sessionHandler)`
    `protected void` | `startContext()` Finish constructing handlers and link them together.

    - ### Methods inherited from class org.eclipse.jetty.server.handler.ContextHandler

      `addAliasCheck, addEventListener, addLocaleEncoding, addVirtualHosts, checkAlias, checkContext, checkManagedAttribute, clearAttributes, doHandle, doScope, doStart, dump, getAliasChecks, getAllowNullPathInfo, getAttribute, getAttributeNames, getAttributes, getBaseResource, getClassLoader, getClassPath, getConnectorNames, getContextPath, getCurrentContext, getDisplayName, getErrorHandler, getEventListeners, getInitParameter, getInitParameterNames, getInitParams, getLocaleEncoding, getLocaleEncoding, getLogger, getMaxFormContentSize, getMaxFormKeys, getMimeTypes, getProtectedTargets, getResource, getResourceBase, getResourcePaths, getServletContext, getVirtualHosts, getWelcomeFiles, handle, isAliases, isAvailable, isCompactPath, isProtectedTarget, isShutdown, loadClass, newResource, newResource, removeAttribute, removeVirtualHosts, setAliases, setAllowNullPathInfo, setAttribute, setAttributes, setAvailable, setBaseResource, setClassLoader, setCompactPath, setConnectorNames, setContextPath, setDisplayName, setErrorHandler, setEventListeners, setInitParameter, setLogger, setManagedAttribute, setMaxFormContentSize, setMaxFormKeys, setMimeTypes, setProtectedTargets, setResourceBase, setServer, setShutdown, setVirtualHosts, setWelcomeFiles, toString`

    - ### Methods inherited from class org.eclipse.jetty.server.handler.ScopedHandler

      `handle, never, nextHandle, nextScope`

    - ### Methods inherited from class org.eclipse.jetty.server.handler.HandlerWrapper

      `destroy, expandChildren, getHandler, getHandlers, getNestedHandlerByClass, setHandler`

    - ### Methods inherited from class org.eclipse.jetty.server.handler.AbstractHandlerContainer

      `expandHandler, findContainerOf, getChildHandlerByClass, getChildHandlers, getChildHandlersByClass`

    - ### Methods inherited from class org.eclipse.jetty.server.handler.AbstractHandler

      `dumpThis, getServer`

    - ### Methods inherited from class org.eclipse.jetty.util.component.AggregateLifeCycle

      `addBean, addBean, contains, dump, dump, dump, dump, dumpObject, dumpStdErr, getBean, getBeans, getBeans, isManaged, manage, removeBean, removeBeans, unmanage`

    - ### Methods inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle

      `addLifeCycleListener, getState, getState, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

    - ### Methods inherited from interface org.eclipse.jetty.server.Handler

      `destroy, getServer, handle`

    - ### Methods inherited from interface org.eclipse.jetty.util.component.LifeCycle

      `addLifeCycleListener, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop`

- - ### Field Detail

    - #### SESSIONS

          public static final int SESSIONS

      See Also:
        Constant Field Values

    - #### SECURITY

          public static final int SECURITY

      See Also:
        Constant Field Values

    - #### NO_SESSIONS

          public static final int NO_SESSIONS

      See Also:
        Constant Field Values

    - #### NO_SECURITY

          public static final int NO_SECURITY

      See Also:
        Constant Field Values

    - #### _decorators

          protected final List<ServletContextHandler.Decorator> _decorators

    - #### _defaultSecurityHandlerClass

          protected Class<? extends SecurityHandler> _defaultSecurityHandlerClass

    - #### _sessionHandler

          protected SessionHandler _sessionHandler

    - #### _securityHandler

          protected SecurityHandler _securityHandler

    - #### _servletHandler

          protected ServletHandler _servletHandler

    - #### _wrapper

          protected HandlerWrapper _wrapper

    - #### _options

          protected int _options

    - #### _restrictedContextListeners

          protected Object _restrictedContextListeners

  - ### Constructor Detail

    - #### ServletContextHandler

          public ServletContextHandler()

    - #### ServletContextHandler

          public ServletContextHandler(int options)

    - #### ServletContextHandler

          public ServletContextHandler(HandlerContainer parent,
                               String contextPath)

    - #### ServletContextHandler

          public ServletContextHandler(HandlerContainer parent,
                               String contextPath,
                               int options)

    - #### ServletContextHandler

          public ServletContextHandler(HandlerContainer parent,
                               String contextPath,
                               boolean sessions,
                               boolean security)

    - #### ServletContextHandler

          public ServletContextHandler(HandlerContainer parent,
                               SessionHandler sessionHandler,
                               SecurityHandler securityHandler,
                               ServletHandler servletHandler,
                               ErrorHandler errorHandler)

    - #### ServletContextHandler

          public ServletContextHandler(HandlerContainer parent,
                               String contextPath,
                               SessionHandler sessionHandler,
                               SecurityHandler securityHandler,
                               ServletHandler servletHandler,
                               ErrorHandler errorHandler)

  - ### Method Detail

    - #### doStop

          protected void doStop()
                         throws Exception

      Description copied from class: `AggregateLifeCycle`
      Stop the joined lifecycle beans in the reverse order they were added.
      Overrides:
        `doStop` in class `ContextHandler`
      Throws:
        `Exception`
      See Also:
        `ContextHandler.doStop()`

    - #### getDefaultSecurityHandlerClass

          public Class<? extends SecurityHandler> getDefaultSecurityHandlerClass()

      Get the defaultSecurityHandlerClass.
      Returns:
        the defaultSecurityHandlerClass

    - #### setDefaultSecurityHandlerClass

          public void setDefaultSecurityHandlerClass(Class<? extends SecurityHandler> defaultSecurityHandlerClass)

      Set the defaultSecurityHandlerClass.
      Parameters:
        `defaultSecurityHandlerClass` - the defaultSecurityHandlerClass to set

    - #### newSessionHandler

          protected SessionHandler newSessionHandler()

    - #### newSecurityHandler

          protected SecurityHandler newSecurityHandler()

    - #### newServletHandler

          protected ServletHandler newServletHandler()

    - #### startContext

          protected void startContext()
                               throws Exception

      Finish constructing handlers and link them together.
      Overrides:
        `startContext` in class `ContextHandler`
      Throws:
        `Exception`
      See Also:
        `ContextHandler.startContext()`

    - #### getSecurityHandler

          public SecurityHandler getSecurityHandler()

      Returns:
        Returns the securityHandler.

    - #### getServletHandler

          public ServletHandler getServletHandler()

      Returns:
        Returns the servletHandler.

    - #### getSessionHandler

          public SessionHandler getSessionHandler()

      Returns:
        Returns the sessionHandler.

    - #### addServlet

          public ServletHolder addServlet(String className,
                                 String pathSpec)

      conveniance method to add a servlet.

    - #### addServlet

          public ServletHolder addServlet(Class<? extends javax.servlet.Servlet> servlet,
                                 String pathSpec)

      conveniance method to add a servlet.

    - #### addServlet

          public void addServlet(ServletHolder servlet,
                        String pathSpec)

      conveniance method to add a servlet.

    - #### addFilter

          public void addFilter(FilterHolder holder,
                       String pathSpec,
                       EnumSet<DispatcherType> dispatches)

      conveniance method to add a filter

    - #### addFilter

          public FilterHolder addFilter(Class<? extends javax.servlet.Filter> filterClass,
                               String pathSpec,
                               EnumSet<DispatcherType> dispatches)

      convenience method to add a filter

    - #### addFilter

          public FilterHolder addFilter(String filterClass,
                               String pathSpec,
                               EnumSet<DispatcherType> dispatches)

      convenience method to add a filter

    - #### addFilter

          public void addFilter(FilterHolder holder,
                       String pathSpec,
                       int dispatches)

      conveniance method to add a filter

    - #### addFilter

          public FilterHolder addFilter(Class<? extends javax.servlet.Filter> filterClass,
                               String pathSpec,
                               int dispatches)

      convenience method to add a filter

    - #### addFilter

          public FilterHolder addFilter(String filterClass,
                               String pathSpec,
                               int dispatches)

      convenience method to add a filter

    - #### callContextInitialized

          public void callContextInitialized(javax.servlet.ServletContextListener l,
                                    javax.servlet.ServletContextEvent e)

    - #### callContextDestroyed

          public void callContextDestroyed(javax.servlet.ServletContextListener l,
                                  javax.servlet.ServletContextEvent e)

    - #### setSessionHandler

          public void setSessionHandler(SessionHandler sessionHandler)

      Parameters:
        `sessionHandler` - The sessionHandler to set.

    - #### setSecurityHandler

          public void setSecurityHandler(SecurityHandler securityHandler)

      Parameters:
        `securityHandler` - The `SecurityHandler` to set on this context.

    - #### setServletHandler

          public void setServletHandler(ServletHandler servletHandler)

      Parameters:
        `servletHandler` - The servletHandler to set.

    - #### getDecorators

          public List<ServletContextHandler.Decorator> getDecorators()

      Returns:
        The decorator list used to resource inject new Filters, Servlets and EventListeners

    - #### setDecorators

          public void setDecorators(List<ServletContextHandler.Decorator> decorators)

      Parameters:
        `decorators` - The lis of `ServletContextHandler.Decorator`s

    - #### addDecorator

          public void addDecorator(ServletContextHandler.Decorator decorator)

      Parameters:
        `decorator` - The decorator to add

Copyright © 1995-2016 Mort Bay Consulting. All Rights Reserved.