ServletContext (Apache Tomcat 8.5.43 API Documentation)

org.apache.catalina.servlet4preview

## Interface ServletContext

- All Superinterfaces:
    ServletContext

  Deprecated.
  This class is not included in Tomcat 9 onwards. Users of this class should normally upgrade to Tomcat 9 and switch to the Servlet 4.0 API. If the functionality is required in Tomcat 8.5, then the Tomcat implementation classes should be used directly. This class may be removed from Tomcat 8.5.x some time after 30 September 2018.

      @Deprecated
      public interface ServletContext
      extends ServletContext

  Provides early access to some parts of the proposed Servlet 4.0 API.

- - ### Field Summary

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

      `ORDERED_LIBS, TEMPDIR`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `ServletRegistration.Dynamic` | `addJspFile(java.lang.String jspName, java.lang.String jspFile)` Deprecated.
    `java.lang.String` | `getRequestCharacterEncoding()` Deprecated. Get the default character encoding for reading request bodies.
    `java.lang.String` | `getResponseCharacterEncoding()` Deprecated. Get the default character encoding for writing response bodies.
    `int` | `getSessionTimeout()` Deprecated. Get the default session timeout.
    `void` | `setRequestCharacterEncoding(java.lang.String encoding)` Deprecated. Set the default character encoding to use for reading request bodies.
    `void` | `setResponseCharacterEncoding(java.lang.String encoding)` Deprecated. Set the default character encoding to use for writing response bodies.
    `void` | `setSessionTimeout(int sessionTimeout)` Deprecated. Set the default session timeout.

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

      `addFilter, addFilter, addFilter, addListener, addListener, addListener, addServlet, addServlet, addServlet, createFilter, createListener, createServlet, declareRoles, getAttribute, getAttributeNames, getClassLoader, getContext, getContextPath, getDefaultSessionTrackingModes, getEffectiveMajorVersion, getEffectiveMinorVersion, getEffectiveSessionTrackingModes, getFilterRegistration, getFilterRegistrations, getInitParameter, getInitParameterNames, getJspConfigDescriptor, getMajorVersion, getMimeType, getMinorVersion, getNamedDispatcher, getRealPath, getRequestDispatcher, getResource, getResourceAsStream, getResourcePaths, getServerInfo, getServlet, getServletContextName, getServletNames, getServletRegistration, getServletRegistrations, getServlets, getSessionCookieConfig, getVirtualServerName, log, log, log, removeAttribute, setAttribute, setInitParameter, setSessionTrackingModes`

- - ### Method Detail

    - #### getSessionTimeout

          int getSessionTimeout()

      Deprecated.
      Get the default session timeout.
      Returns:
        The current default session timeout in minutes
      Throws:
        `java.lang.UnsupportedOperationException` - If called from a `ServletContextListener.contextInitialized(ServletContextEvent)` method of a `ServletContextListener` that was not defined in a web.xml file, a web-fragment.xml file nor annotated with `WebListener`. For example, a `ServletContextListener` defined in a TLD would not be able to use this method.
      Since:
        Servlet 4.0

    - #### setSessionTimeout

          void setSessionTimeout(int sessionTimeout)

      Deprecated.
      Set the default session timeout. This method may only be called before the ServletContext is initialised.
      Parameters:
        `sessionTimeout` - The new default session timeout in minutes.
      Throws:
        `java.lang.UnsupportedOperationException` - If called from a `ServletContextListener.contextInitialized(ServletContextEvent)` method of a `ServletContextListener` that was not defined in a web.xml file, a web-fragment.xml file nor annotated with `WebListener`. For example, a `ServletContextListener` defined in a TLD would not be able to use this method.
        `java.lang.IllegalStateException` - If the ServletContext has already been initialised
      Since:
        Servlet 4.0

    - #### addJspFile

          ServletRegistration.Dynamic addJspFile(java.lang.String jspName,
                                               java.lang.String jspFile)

      Deprecated.
      Parameters:
        `jspName` - The servlet name under which this JSP file should be registered
        `jspFile` - The path, relative to the web application root, for the JSP file to be used for this servlet
      Returns:
        a `ServletRegistration.Dynamic` object that can be used to further configure the servlet
      Since:
        Servlet 4.0

    - #### getRequestCharacterEncoding

          java.lang.String getRequestCharacterEncoding()

      Deprecated.
      Get the default character encoding for reading request bodies.
      Returns:
        The character encoding name or `null` if no default has been specified
      Throws:
        `java.lang.UnsupportedOperationException` - If called from a `ServletContextListener.contextInitialized(ServletContextEvent)` method of a `ServletContextListener` that was not defined in a web.xml file, a web-fragment.xml file nor annotated with `WebListener`. For example, a `ServletContextListener` defined in a TLD would not be able to use this method.
      Since:
        Servlet 4.0

    - #### setRequestCharacterEncoding

          void setRequestCharacterEncoding(java.lang.String encoding)

      Deprecated.
      Set the default character encoding to use for reading request bodies. Calling this method will over-ride any value set in the deployment descriptor.
      Parameters:
        `encoding` - The name of the character encoding to use
      Throws:
        `java.lang.UnsupportedOperationException` - If called from a `ServletContextListener.contextInitialized(ServletContextEvent)` method of a `ServletContextListener` that was not defined in a web.xml file, a web-fragment.xml file nor annotated with `WebListener`. For example, a `ServletContextListener` defined in a TLD would not be able to use this method.
        `java.lang.IllegalStateException` - If the ServletContext has already been initialised
      Since:
        Servlet 4.0

    - #### getResponseCharacterEncoding

          java.lang.String getResponseCharacterEncoding()

      Deprecated.
      Get the default character encoding for writing response bodies.
      Returns:
        The character encoding name or `null` if no default has been specified
      Throws:
        `java.lang.UnsupportedOperationException` - If called from a `ServletContextListener.contextInitialized(ServletContextEvent)` method of a `ServletContextListener` that was not defined in a web.xml file, a web-fragment.xml file nor annotated with `WebListener`. For example, a `ServletContextListener` defined in a TLD would not be able to use this method.
      Since:
        Servlet 4.0

    - #### setResponseCharacterEncoding

          void setResponseCharacterEncoding(java.lang.String encoding)

      Deprecated.
      Set the default character encoding to use for writing response bodies. Calling this method will over-ride any value set in the deployment descriptor.
      Parameters:
        `encoding` - The name of the character encoding to use
      Throws:
        `java.lang.UnsupportedOperationException` - If called from a `ServletContextListener.contextInitialized(ServletContextEvent)` method of a `ServletContextListener` that was not defined in a web.xml file, a web-fragment.xml file nor annotated with `WebListener`. For example, a `ServletContextListener` defined in a TLD would not be able to use this method.
        `java.lang.IllegalStateException` - If the ServletContext has already been initialised
      Since:
        Servlet 4.0

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