org.apache.jasper.servlet

## Class JspCServletContext

- java.lang.Object
- - org.apache.jasper.servlet.JspCServletContext

- All Implemented Interfaces:
    ServletContext

      public class JspCServletContext
      extends Object
      implements ServletContext

  Simple `ServletContext` implementation without HTTP-specific methods.
  Author:
    Peter Rossbach (pr@webapp.de)

- - ### Field Summary

    - ### Fields inherited from interface javax.servlet.ServletContext

      `ORDERED_LIBS, TEMPDIR`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `JspCServletContext(PrintWriter aLogWriter, URL aResourceBaseURL, ClassLoader classLoader, boolean validate, boolean blockExternal)` Create a new instance of this ServletContext implementation.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `FilterRegistration.Dynamic` | `addFilter(String filterName, Class<? extends Filter> filterClass)` Add filter to context.
    `FilterRegistration.Dynamic` | `addFilter(String filterName, Filter filter)` Add filter to context.
    `FilterRegistration.Dynamic` | `addFilter(String filterName, String className)` Add filter to context.
    `void` | `addListener(Class<? extends EventListener> listenerClass)` TODO SERVLET3 - Add comments
    `void` | `addListener(String className)` TODO SERVLET3 - Add comments
    `<T extends EventListener> void` | `addListener(T t)` TODO SERVLET3 - Add comments
    `ServletRegistration.Dynamic` | `addServlet(String servletName, Class<? extends Servlet> servletClass)` Add servlet to context.
    `ServletRegistration.Dynamic` | `addServlet(String servletName, Servlet servlet)` Register a servlet instance for use in this ServletContext.
    `ServletRegistration.Dynamic` | `addServlet(String servletName, String className)` Register a servlet implementation for use in this ServletContext.
    `<T extends Filter> T` | `createFilter(Class<T> c)` TODO SERVLET3 - Add comments
    `<T extends EventListener> T` | `createListener(Class<T> c)` TODO SERVLET3 - Add comments
    `<T extends Servlet> T` | `createServlet(Class<T> c)` TODO SERVLET3 - Add comments
    `void` | `declareRoles(String... roleNames)` Add to the declared roles for this ServletContext.
    `Object` | `getAttribute(String name)` Return the specified context attribute, if any.
    `Enumeration<String>` | `getAttributeNames()` Return an enumeration of context attribute names.
    `ClassLoader` | `getClassLoader()` Get the web application class loader associated with this ServletContext.
    `ServletContext` | `getContext(String uripath)` Return the servlet context for the specified path.
    `String` | `getContextPath()` Return the context path.
    `Set<SessionTrackingMode>` | `getDefaultSessionTrackingModes()` Obtains the default session tracking modes for this web application.
    `int` | `getEffectiveMajorVersion()`
    `int` | `getEffectiveMinorVersion()`
    `Set<SessionTrackingMode>` | `getEffectiveSessionTrackingModes()` Obtains the currently enabled session tracking modes for this web application.
    `FilterRegistration` | `getFilterRegistration(String filterName)` TODO SERVLET3 - Add comments
    `Map<String,? extends FilterRegistration>` | `getFilterRegistrations()`
    `String` | `getInitParameter(String name)` Return the specified context initialization parameter.
    `Enumeration<String>` | `getInitParameterNames()` Return an enumeration of the names of context initialization parameters.
    `JspConfigDescriptor` | `getJspConfigDescriptor()`
    `int` | `getMajorVersion()` Return the Servlet API major version number.
    `String` | `getMimeType(String file)` Return the MIME type for the specified filename.
    `int` | `getMinorVersion()` Return the Servlet API minor version number.
    `RequestDispatcher` | `getNamedDispatcher(String name)` Return a request dispatcher for the specified servlet name.
    `String` | `getRealPath(String path)` Return the real path for the specified context-relative virtual path.
    `RequestDispatcher` | `getRequestDispatcher(String path)` Return a request dispatcher for the specified context-relative path.
    `URL` | `getResource(String path)` Return a URL object of a resource that is mapped to the specified context-relative path.
    `InputStream` | `getResourceAsStream(String path)` Return an InputStream allowing access to the resource at the specified context-relative path.
    `Set<String>` | `getResourcePaths(String path)` Return the set of resource paths for the "directory" at the specified context path.
    `String` | `getServerInfo()` Return descriptive information about this server.
    `Servlet` | `getServlet(String name)` Deprecated. This method has been deprecated with no replacement
    `String` | `getServletContextName()` Return the name of this servlet context.
    `Enumeration<String>` | `getServletNames()` Deprecated. This method has been deprecated with no replacement
    `ServletRegistration` | `getServletRegistration(String servletName)` Obtain the details of the named servlet.
    `Map<String,? extends ServletRegistration>` | `getServletRegistrations()` TODO SERVLET3 - Add comments
    `Enumeration<Servlet>` | `getServlets()` Deprecated. This method has been deprecated with no replacement
    `SessionCookieConfig` | `getSessionCookieConfig()`
    `String` | `getVirtualServerName()` Get the primary name of the virtual host on which this context is deployed.
    `void` | `log(Exception exception, String message)` Deprecated. Use log(String,Throwable) instead
    `void` | `log(String message)` Log the specified message.
    `void` | `log(String message, Throwable exception)` Log the specified message and exception.
    `void` | `removeAttribute(String name)` Remove the specified context attribute.
    `void` | `setAttribute(String name, Object value)` Set or replace the specified context attribute.
    `boolean` | `setInitParameter(String name, String value)` Set the given initialisation parameter to the given value.
    `void` | `setSessionTrackingModes(Set<SessionTrackingMode> sessionTrackingModes)` Configures the available session tracking modes for this web application.

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

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

- - ### Constructor Detail

    - #### JspCServletContext

          public JspCServletContext(PrintWriter aLogWriter,
                            URL aResourceBaseURL,
                            ClassLoader classLoader,
                            boolean validate,
                            boolean blockExternal)
                             throws JasperException

      Create a new instance of this ServletContext implementation.
      Parameters:
        `aLogWriter` - PrintWriter which is used for `log()` calls
        `aResourceBaseURL` - Resource base URL
        `classLoader` - Class loader for this `ServletContext`
        `validate` - Should a validating parser be used to parse web.xml?
        `blockExternal` - Should external entities be blocked when parsing web.xml?
      Throws:
        `JasperException` - An error occurred building the merged web.xml

  - ### Method Detail

    - #### getAttribute

          public Object getAttribute(String name)

      Return the specified context attribute, if any.
      Specified by:
        `getAttribute` in interface `ServletContext`
      Parameters:
        `name` - Name of the requested attribute
      Returns:
        an `Object` containing the value of the attribute, or `null` if no attribute exists matching the given name
      See Also:
        `ServletContext.getAttributeNames()`

    - #### getAttributeNames

          public Enumeration<String> getAttributeNames()

      Return an enumeration of context attribute names.
      Specified by:
        `getAttributeNames` in interface `ServletContext`
      Returns:
        an `Enumeration` of attribute names
      See Also:
        `ServletContext.getAttribute(java.lang.String)`

    - #### getContext

          public ServletContext getContext(String uripath)

      Return the servlet context for the specified path.
      Specified by:
        `getContext` in interface `ServletContext`
      Parameters:
        `uripath` - Server-relative path starting with '/'
      Returns:
        the `ServletContext` object that corresponds to the named URL, or null if either none exists or the container wishes to restrict this access.
      See Also:
        `RequestDispatcher`

    - #### getContextPath

          public String getContextPath()

      Return the context path.
      Specified by:
        `getContextPath` in interface `ServletContext`
      Returns:
        The main context path

    - #### getInitParameter

          public String getInitParameter(String name)

      Return the specified context initialization parameter.
      Specified by:
        `getInitParameter` in interface `ServletContext`
      Parameters:
        `name` - Name of the requested parameter
      Returns:
        a `String` containing the value of the initialization parameter
      See Also:
        `ServletConfig.getInitParameter(java.lang.String)`

    - #### getInitParameterNames

          public Enumeration<String> getInitParameterNames()

      Return an enumeration of the names of context initialization parameters.
      Specified by:
        `getInitParameterNames` in interface `ServletContext`
      Returns:
        an `Enumeration` of `String` objects containing the names of the context's initialization parameters
      See Also:
        `ServletConfig.getInitParameter(java.lang.String)`

    - #### getMajorVersion

          public int getMajorVersion()

      Return the Servlet API major version number.
      Specified by:
        `getMajorVersion` in interface `ServletContext`
      Returns:
        3

    - #### getMimeType

          public String getMimeType(String file)

      Return the MIME type for the specified filename.
      Specified by:
        `getMimeType` in interface `ServletContext`
      Parameters:
        `file` - Filename whose MIME type is requested
      Returns:
        a `String` specifying the file's MIME type

    - #### getMinorVersion

          public int getMinorVersion()

      Return the Servlet API minor version number.
      Specified by:
        `getMinorVersion` in interface `ServletContext`
      Returns:
        1

    - #### getNamedDispatcher

          public RequestDispatcher getNamedDispatcher(String name)

      Return a request dispatcher for the specified servlet name.
      Specified by:
        `getNamedDispatcher` in interface `ServletContext`
      Parameters:
        `name` - Name of the requested servlet
      Returns:
        a `RequestDispatcher` object that acts as a wrapper for the named servlet, or `null` if the `ServletContext` cannot return a `RequestDispatcher`
      See Also:
        `RequestDispatcher`, `ServletContext.getContext(java.lang.String)`, `ServletConfig.getServletName()`

    - #### getRealPath

          public String getRealPath(String path)

      Return the real path for the specified context-relative virtual path.
      Specified by:
        `getRealPath` in interface `ServletContext`
      Parameters:
        `path` - The context-relative virtual path to resolve
      Returns:
        a `String` specifying the real path, or null if the translation cannot be performed

    - #### getRequestDispatcher

          public RequestDispatcher getRequestDispatcher(String path)

      Return a request dispatcher for the specified context-relative path.
      Specified by:
        `getRequestDispatcher` in interface `ServletContext`
      Parameters:
        `path` - Context-relative path for which to acquire a dispatcher
      Returns:
        a `RequestDispatcher` object that acts as a wrapper for the resource at the specified path, or `null` if the `ServletContext` cannot return a `RequestDispatcher`
      See Also:
        `RequestDispatcher`, `ServletContext.getContext(java.lang.String)`

    - #### getResource

          public URL getResource(String path)
                          throws MalformedURLException

      Return a URL object of a resource that is mapped to the specified context-relative path.
      Specified by:
        `getResource` in interface `ServletContext`
      Parameters:
        `path` - Context-relative path of the desired resource
      Returns:
        the resource located at the named path, or `null` if there is no resource at that path
      Throws:
        `MalformedURLException` - if the resource path is not properly formed

    - #### getResourceAsStream

          public InputStream getResourceAsStream(String path)

      Return an InputStream allowing access to the resource at the specified context-relative path.
      Specified by:
        `getResourceAsStream` in interface `ServletContext`
      Parameters:
        `path` - Context-relative path of the desired resource
      Returns:
        the `InputStream` returned to the servlet, or `null` if no resource exists at the specified path

    - #### getResourcePaths

          public Set<String> getResourcePaths(String path)

      Return the set of resource paths for the "directory" at the specified context path.
      Specified by:
        `getResourcePaths` in interface `ServletContext`
      Parameters:
        `path` - Context-relative base path
      Returns:
        a Set containing the directory listing, or null if there are no resources in the web application whose path begins with the supplied path.

    - #### getServerInfo

          public String getServerInfo()

      Return descriptive information about this server.
      Specified by:
        `getServerInfo` in interface `ServletContext`
      Returns:
        a `String` containing at least the servlet container name and version number

    - #### getServlet

          @Deprecated
          public Servlet getServlet(String name)
                             throws ServletException

      Deprecated. This method has been deprecated with no replacement
      Return a null reference for the specified servlet name.
      Specified by:
        `getServlet` in interface `ServletContext`
      Parameters:
        `name` - Name of the requested servlet
      Returns:
        Always `null`
      Throws:
        `ServletException` - never

    - #### getServletContextName

          public String getServletContextName()

      Return the name of this servlet context.
      Specified by:
        `getServletContextName` in interface `ServletContext`
      Returns:
        The name of the web application or null if no name has been declared in the deployment descriptor.

    - #### getServletNames

          @Deprecated
          public Enumeration<String> getServletNames()

      Deprecated. This method has been deprecated with no replacement
      Return an empty enumeration of servlet names.
      Specified by:
        `getServletNames` in interface `ServletContext`
      Returns:
        Always and empty Enumeration

    - #### getServlets

          @Deprecated
          public Enumeration<Servlet> getServlets()

      Deprecated. This method has been deprecated with no replacement
      Return an empty enumeration of servlets.
      Specified by:
        `getServlets` in interface `ServletContext`
      Returns:
        Always and empty Enumeration

    - #### log

          public void log(String message)

      Log the specified message.
      Specified by:
        `log` in interface `ServletContext`
      Parameters:
        `message` - The message to be logged

    - #### log

          @Deprecated
          public void log(Exception exception,
                            String message)

      Deprecated. Use log(String,Throwable) instead
      Log the specified message and exception.
      Specified by:
        `log` in interface `ServletContext`
      Parameters:
        `exception` - The exception to be logged
        `message` - The message to be logged

    - #### log

          public void log(String message,
                 Throwable exception)

      Log the specified message and exception.
      Specified by:
        `log` in interface `ServletContext`
      Parameters:
        `message` - The message to be logged
        `exception` - The exception to be logged

    - #### removeAttribute

          public void removeAttribute(String name)

      Remove the specified context attribute.
      Specified by:
        `removeAttribute` in interface `ServletContext`
      Parameters:
        `name` - Name of the attribute to remove

    - #### setAttribute

          public void setAttribute(String name,
                          Object value)

      Set or replace the specified context attribute.
      Specified by:
        `setAttribute` in interface `ServletContext`
      Parameters:
        `name` - Name of the context attribute to set
        `value` - Corresponding attribute value

    - #### addFilter

          public FilterRegistration.Dynamic addFilter(String filterName,
                                             String className)

      Description copied from interface: `javax.servlet.ServletContext`
      Add filter to context.
      Specified by:
        `addFilter` in interface `ServletContext`
      Parameters:
        `filterName` - Name of filter to add
        `className` - Name of filter class
      Returns:
        `null` if the filter has already been fully defined, else a `FilterRegistration.Dynamic` object that can be used to further configure the filter

    - #### addServlet

          public ServletRegistration.Dynamic addServlet(String servletName,
                                               String className)

      Description copied from interface: `javax.servlet.ServletContext`
      Register a servlet implementation for use in this ServletContext.
      Specified by:
        `addServlet` in interface `ServletContext`
      Parameters:
        `servletName` - The name of the servlet to register
        `className` - The implementation class for the servlet
      Returns:
        The registration object that enables further configuration

    - #### getDefaultSessionTrackingModes

          public Set<SessionTrackingMode> getDefaultSessionTrackingModes()

      Description copied from interface: `javax.servlet.ServletContext`
      Obtains the default session tracking modes for this web application. By default `SessionTrackingMode.URL` is always supported, `SessionTrackingMode.COOKIE` is supported unless the `cookies` attribute has been set to `false` for the context and `SessionTrackingMode.SSL` is supported if at least one of the connectors used by this context has the attribute `secure` set to `true`.
      Specified by:
        `getDefaultSessionTrackingModes` in interface `ServletContext`
      Returns:
        The set of default session tracking modes for this web application

    - #### getEffectiveSessionTrackingModes

          public Set<SessionTrackingMode> getEffectiveSessionTrackingModes()

      Description copied from interface: `javax.servlet.ServletContext`
      Obtains the currently enabled session tracking modes for this web application.
      Specified by:
        `getEffectiveSessionTrackingModes` in interface `ServletContext`
      Returns:
        The value supplied via `ServletContext.setSessionTrackingModes(Set)` if one was previously set, else return the defaults

    - #### getSessionCookieConfig

          public SessionCookieConfig getSessionCookieConfig()

      Specified by:
        `getSessionCookieConfig` in interface `ServletContext`
      Returns:
        TODO

    - #### setSessionTrackingModes

          public void setSessionTrackingModes(Set<SessionTrackingMode> sessionTrackingModes)

      Description copied from interface: `javax.servlet.ServletContext`
      Configures the available session tracking modes for this web application.
      Specified by:
        `setSessionTrackingModes` in interface `ServletContext`
      Parameters:
        `sessionTrackingModes` - The session tracking modes to use for this web application

    - #### addFilter

          public FilterRegistration.Dynamic addFilter(String filterName,
                                             Filter filter)

      Description copied from interface: `javax.servlet.ServletContext`
      Add filter to context.
      Specified by:
        `addFilter` in interface `ServletContext`
      Parameters:
        `filterName` - Name of filter to add
        `filter` - Filter to add
      Returns:
        `null` if the filter has already been fully defined, else a `FilterRegistration.Dynamic` object that can be used to further configure the filter

    - #### addFilter

          public FilterRegistration.Dynamic addFilter(String filterName,
                                             Class<? extends Filter> filterClass)

      Description copied from interface: `javax.servlet.ServletContext`
      Add filter to context.
      Specified by:
        `addFilter` in interface `ServletContext`
      Parameters:
        `filterName` - Name of filter to add
        `filterClass` - Class of filter to add
      Returns:
        `null` if the filter has already been fully defined, else a `FilterRegistration.Dynamic` object that can be used to further configure the filter

    - #### addServlet

          public ServletRegistration.Dynamic addServlet(String servletName,
                                               Servlet servlet)

      Description copied from interface: `javax.servlet.ServletContext`
      Register a servlet instance for use in this ServletContext.
      Specified by:
        `addServlet` in interface `ServletContext`
      Parameters:
        `servletName` - The name of the servlet to register
        `servlet` - The Servlet instance to register
      Returns:
        The registration object that enables further configuration

    - #### addServlet

          public ServletRegistration.Dynamic addServlet(String servletName,
                                               Class<? extends Servlet> servletClass)

      Description copied from interface: `javax.servlet.ServletContext`
      Add servlet to context.
      Specified by:
        `addServlet` in interface `ServletContext`
      Parameters:
        `servletName` - Name of servlet to add
        `servletClass` - Class of servlet to add
      Returns:
        `null` if the servlet has already been fully defined, else a `ServletRegistration.Dynamic` object that can be used to further configure the servlet

    - #### createFilter

          public <T extends Filter> T createFilter(Class<T> c)
                                        throws ServletException

      Description copied from interface: `javax.servlet.ServletContext`
      TODO SERVLET3 - Add comments
      Specified by:
        `createFilter` in interface `ServletContext`
      Type Parameters:
        `T` - TODO
      Parameters:
        `c` - TODO
      Returns:
        TODO
      Throws:
        `ServletException` - TODO

    - #### createServlet

          public <T extends Servlet> T createServlet(Class<T> c)
                                          throws ServletException

      Description copied from interface: `javax.servlet.ServletContext`
      TODO SERVLET3 - Add comments
      Specified by:
        `createServlet` in interface `ServletContext`
      Type Parameters:
        `T` - TODO
      Parameters:
        `c` - TODO
      Returns:
        TODO
      Throws:
        `ServletException` - TODO

    - #### getFilterRegistration

          public FilterRegistration getFilterRegistration(String filterName)

      Description copied from interface: `javax.servlet.ServletContext`
      TODO SERVLET3 - Add comments
      Specified by:
        `getFilterRegistration` in interface `ServletContext`
      Parameters:
        `filterName` - TODO
      Returns:
        TODO

    - #### getServletRegistration

          public ServletRegistration getServletRegistration(String servletName)

      Description copied from interface: `javax.servlet.ServletContext`
      Obtain the details of the named servlet.
      Specified by:
        `getServletRegistration` in interface `ServletContext`
      Parameters:
        `servletName` - The name of the Servlet of interest
      Returns:
        The registration details for the named Servlet or `null` if no Servlet has been registered with the given name

    - #### setInitParameter

          public boolean setInitParameter(String name,
                                 String value)

      Description copied from interface: `javax.servlet.ServletContext`
      Set the given initialisation parameter to the given value.
      Specified by:
        `setInitParameter` in interface `ServletContext`
      Parameters:
        `name` - Name of initialisation parameter
        `value` - Value for initialisation parameter
      Returns:
        `true` if the call succeeds or `false` if the call fails because an initialisation parameter with the same name has already been set

    - #### addListener

          public void addListener(Class<? extends EventListener> listenerClass)

      Description copied from interface: `javax.servlet.ServletContext`
      TODO SERVLET3 - Add comments
      Specified by:
        `addListener` in interface `ServletContext`
      Parameters:
        `listenerClass` - TODO

    - #### addListener

          public void addListener(String className)

      Description copied from interface: `javax.servlet.ServletContext`
      TODO SERVLET3 - Add comments
      Specified by:
        `addListener` in interface `ServletContext`
      Parameters:
        `className` - TODO

    - #### addListener

          public <T extends EventListener> void addListener(T t)

      Description copied from interface: `javax.servlet.ServletContext`
      TODO SERVLET3 - Add comments
      Specified by:
        `addListener` in interface `ServletContext`
      Type Parameters:
        `T` - TODO
      Parameters:
        `t` - TODO

    - #### createListener

          public <T extends EventListener> T createListener(Class<T> c)
                                                 throws ServletException

      Description copied from interface: `javax.servlet.ServletContext`
      TODO SERVLET3 - Add comments
      Specified by:
        `createListener` in interface `ServletContext`
      Type Parameters:
        `T` - TODO
      Parameters:
        `c` - TODO
      Returns:
        TODO
      Throws:
        `ServletException` - TODO

    - #### declareRoles

          public void declareRoles(String... roleNames)

      Description copied from interface: `javax.servlet.ServletContext`
      Add to the declared roles for this ServletContext.
      Specified by:
        `declareRoles` in interface `ServletContext`
      Parameters:
        `roleNames` - The roles to add

    - #### getClassLoader

          public ClassLoader getClassLoader()

      Description copied from interface: `javax.servlet.ServletContext`
      Get the web application class loader associated with this ServletContext.
      Specified by:
        `getClassLoader` in interface `ServletContext`
      Returns:
        The associated web application class loader

    - #### getEffectiveMajorVersion

          public int getEffectiveMajorVersion()

      Specified by:
        `getEffectiveMajorVersion` in interface `ServletContext`
      Returns:
        TODO

    - #### getEffectiveMinorVersion

          public int getEffectiveMinorVersion()

      Specified by:
        `getEffectiveMinorVersion` in interface `ServletContext`
      Returns:
        TODO

    - #### getFilterRegistrations

          public Map<String,? extends FilterRegistration> getFilterRegistrations()

      Specified by:
        `getFilterRegistrations` in interface `ServletContext`
      Returns:
        TODO

    - #### getJspConfigDescriptor

          public JspConfigDescriptor getJspConfigDescriptor()

      Specified by:
        `getJspConfigDescriptor` in interface `ServletContext`
      Returns:
        TODO

    - #### getServletRegistrations

          public Map<String,? extends ServletRegistration> getServletRegistrations()

      Description copied from interface: `javax.servlet.ServletContext`
      TODO SERVLET3 - Add comments
      Specified by:
        `getServletRegistrations` in interface `ServletContext`
      Returns:
        TODO

    - #### getVirtualServerName

          public String getVirtualServerName()

      Description copied from interface: `javax.servlet.ServletContext`
      Get the primary name of the virtual host on which this context is deployed. The name may or may not be a valid host name.
      Specified by:
        `getVirtualServerName` in interface `ServletContext`
      Returns:
        The primary name of the virtual host on which this context is deployed

Copyright © 2000-2017 Apache Software Foundation. All Rights Reserved.