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
`class` `ServletContextHandler.Context`
`static interface` `ServletContextHandler.Decorator` Interface to decorate loaded classes.
`static class` `ServletContextHandler.JspConfig`
`static class` `ServletContextHandler.JspPropertyGroup`
`static class` `ServletContextHandler.TagLib`

### 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
`protected List<ServletContextHandler.Decorator>` `_decorators`
`protected Class<? extends SecurityHandler>` `_defaultSecurityHandlerClass`
`protected javax.servlet.descriptor.JspConfigDescriptor` `_jspConfig`
`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
`void` `addDecorator(ServletContextHandler.Decorator decorator)`
`FilterHolder` `addFilter(Class<? extends javax.servlet.Filter> filterClass, String pathSpec, EnumSet<javax.servlet.DispatcherType> dispatches)` convenience method to add a filter
`void` `addFilter(FilterHolder holder, String pathSpec, EnumSet<javax.servlet.DispatcherType> dispatches)` conveniance method to add a filter
`FilterHolder` `addFilter(String filterClass, String pathSpec, EnumSet<javax.servlet.DispatcherType> dispatches)` convenience method to add a filter
`protected void` `addRoles(String... roleNames)` delegate for ServletContext.declareRole method
`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.
`protected javax.servlet.ServletRegistration.Dynamic` `dynamicHolderAdded(ServletHolder holder)` notification that a ServletRegistration has been created so we can track the annotations
`List<ServletContextHandler.Decorator>` `getDecorators()`
`Class<? extends SecurityHandler>` `getDefaultSecurityHandlerClass()` Get the defaultSecurityHandlerClass.
`SecurityHandler` `getSecurityHandler()`
`ServletHandler` `getServletHandler()`
`SessionHandler` `getSessionHandler()`
`boolean` `isRestrictListeners()`
`protected SecurityHandler` `newSecurityHandler()`
`protected ServletHandler` `newServletHandler()`
`protected SessionHandler` `newSessionHandler()`
`void` `restrictEventListener(EventListener e)` Apply any necessary restrictions on a programmatically added listener.
`void` `setDecorators(List<ServletContextHandler.Decorator> decorators)`
`void` `setDefaultSecurityHandlerClass(Class<? extends SecurityHandler> defaultSecurityHandlerClass)` Set the defaultSecurityHandlerClass.
`void` `setRestrictListeners(boolean restrictListeners)`
`void` `setSecurityHandler(SecurityHandler securityHandler)`
`void` `setServletHandler(ServletHandler servletHandler)`
`Set<String>` `setServletSecurity(javax.servlet.ServletRegistration.Dynamic registration, javax.servlet.ServletSecurityElement servletSecurityElement)` Delegate for ServletRegistration.Dynamic.setServletSecurity method
`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, 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

#### _jspConfig

    protected javax.servlet.descriptor.JspConfigDescriptor _jspConfig

#### _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<javax.servlet.DispatcherType> dispatches)

conveniance method to add a filter

#### addFilter

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

convenience method to add a filter

#### addFilter

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

convenience method to add a filter

#### dynamicHolderAdded

    protected javax.servlet.ServletRegistration.Dynamic dynamicHolderAdded(ServletHolder holder)

notification that a ServletRegistration has been created so we can track the annotations

Parameters:
  `holder` - new holder created through the api.
Returns:
  the ServletRegistration.Dynamic

#### addRoles

    protected void addRoles(String... roleNames)

delegate for ServletContext.declareRole method

Parameters:
  `roleNames` - role names to add

#### setServletSecurity

    public Set<String> setServletSecurity(javax.servlet.ServletRegistration.Dynamic registration,
                                 javax.servlet.ServletSecurityElement servletSecurityElement)

Delegate for ServletRegistration.Dynamic.setServletSecurity method

Parameters:
  `registration` - ServletRegistration.Dynamic instance that setServletSecurity was called on
  `servletSecurityElement` - new security info
Returns:
  the set of exact URL mappings currently associated with the registration that are also present in the web.xml security constraints and thus will be unaffected by this call.

#### restrictEventListener

    public void restrictEventListener(EventListener e)

Description copied from class: `ContextHandler`
Apply any necessary restrictions on a programmatically added listener. Superclasses should implement.

Overrides:
  `restrictEventListener` in class `ContextHandler`

#### isRestrictListeners

    public boolean isRestrictListeners()

#### setRestrictListeners

    public void setRestrictListeners(boolean restrictListeners)

#### callContextInitialized

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

Overrides:
  `callContextInitialized` in class `ContextHandler`

#### callContextDestroyed

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

Overrides:
  `callContextDestroyed` in class `ContextHandler`

#### 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