类 ServletContextResource

java.lang.Object
cn.taketoday.core.io.AbstractResource
cn.taketoday.core.io.AbstractFileResolvingResource
cn.taketoday.web.servlet.support.ServletContextResource
所有已实现的接口:
cn.taketoday.core.io.ContextResource, cn.taketoday.core.io.InputStreamSource, cn.taketoday.core.io.Resource

public class ServletContextResource extends cn.taketoday.core.io.AbstractFileResolvingResource implements cn.taketoday.core.io.ContextResource
Resource implementation for ServletContext resources, interpreting relative paths within the web application root directory.

Always supports stream access and URL access, but only allows java.io.File access when the web application archive is expanded.

从以下版本开始:
4.0 2022/2/20 16:27
作者:
Juergen Hoeller, Harry Yang
另请参阅:
  • 字段概要

    字段
    修饰符和类型
    字段
    说明
    private final String
     
    private final ServletContext
     

    从接口继承的字段 cn.taketoday.core.io.Resource

    EMPTY_ARRAY
  • 构造器概要

    构造器
    构造器
    说明
    Create a new ServletContextResource.
  • 方法概要

    修饰符和类型
    方法
    说明
    cn.taketoday.core.io.Resource
    createRelative(String relativePath)
    This implementation creates a ServletContextResource, applying the given path relative to the path of the underlying file of this resource descriptor.
    boolean
    equals(Object other)
    This implementation compares the underlying ServletContext resource locations.
    boolean
    This implementation checks ServletContext.getResource.
    This implementation resolves "file:" URLs or alternatively delegates to ServletContext.getRealPath, throwing a FileNotFoundException if not found or not resolvable.
    This implementation delegates to ServletContext.getResourceAsStream, but throws a FileNotFoundException if no resource found.
    This implementation returns the name of the file that this ServletContext resource refers to.
    final String
    Return the path for this resource.
     
    Return the ServletContext for this resource.
    This implementation delegates to ServletContext.getResource, but throws a FileNotFoundException if no resource found.
    int
    This implementation returns the hash code of the underlying ServletContext resource location.
    boolean
     
    boolean
    This implementation delegates to ServletContext.getResourceAsStream, which returns null in case of a non-readable resource (e.g. a directory).
    This implementation returns a description that includes the ServletContext resource location.

    从类继承的方法 cn.taketoday.core.io.AbstractFileResolvingResource

    contentLength, customizeConnection, customizeConnection, getFile, getFileForLastModifiedCheck, isFile, lastModified, readableChannel

    从类继承的方法 cn.taketoday.core.io.AbstractResource

    getURI, isDirectory, isOpen, list, list

    从类继承的方法 java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait

    从接口继承的方法 cn.taketoday.core.io.InputStreamSource

    getReader, getReader, readableChannel

    从接口继承的方法 cn.taketoday.core.io.Resource

    contentLength, getContentAsByteArray, getContentAsString, getURI, isDirectory, isOpen, lastModified, list, list
  • 字段详细资料

  • 构造器详细资料

    • ServletContextResource

      public ServletContextResource(ServletContext servletContext, String path)
      Create a new ServletContextResource.

      The Servlet spec requires that resource paths start with a slash, even if many containers accept paths without leading slash too. Consequently, the given path will be prepended with a slash if it doesn't already start with one.

      参数:
      servletContext - the ServletContext to load from
      path - the path of the resource
  • 方法详细资料

    • getServletContext

      public final ServletContext getServletContext()
      Return the ServletContext for this resource.
    • getPath

      public final String getPath()
      Return the path for this resource.
    • exists

      public boolean exists()
      This implementation checks ServletContext.getResource.
      指定者:
      exists 在接口中 cn.taketoday.core.io.Resource
      覆盖:
      exists 在类中 cn.taketoday.core.io.AbstractFileResolvingResource
      另请参阅:
    • isReadable

      public boolean isReadable()
      This implementation delegates to ServletContext.getResourceAsStream, which returns null in case of a non-readable resource (e.g. a directory).
      指定者:
      isReadable 在接口中 cn.taketoday.core.io.Resource
      覆盖:
      isReadable 在类中 cn.taketoday.core.io.AbstractFileResolvingResource
      另请参阅:
    • isFile

      public boolean isFile()
      指定者:
      isFile 在接口中 cn.taketoday.core.io.Resource
      覆盖:
      isFile 在类中 cn.taketoday.core.io.AbstractFileResolvingResource
    • getInputStream

      public InputStream getInputStream() throws IOException
      This implementation delegates to ServletContext.getResourceAsStream, but throws a FileNotFoundException if no resource found.
      指定者:
      getInputStream 在接口中 cn.taketoday.core.io.InputStreamSource
      抛出:
      IOException
      另请参阅:
    • getURL

      public URL getURL() throws IOException
      This implementation delegates to ServletContext.getResource, but throws a FileNotFoundException if no resource found.
      指定者:
      getURL 在接口中 cn.taketoday.core.io.Resource
      覆盖:
      getURL 在类中 cn.taketoday.core.io.AbstractResource
      抛出:
      IOException
      另请参阅:
    • getFile

      public File getFile() throws IOException
      This implementation resolves "file:" URLs or alternatively delegates to ServletContext.getRealPath, throwing a FileNotFoundException if not found or not resolvable.
      指定者:
      getFile 在接口中 cn.taketoday.core.io.Resource
      覆盖:
      getFile 在类中 cn.taketoday.core.io.AbstractFileResolvingResource
      抛出:
      IOException
      另请参阅:
    • createRelative

      public cn.taketoday.core.io.Resource createRelative(String relativePath)
      This implementation creates a ServletContextResource, applying the given path relative to the path of the underlying file of this resource descriptor.
      指定者:
      createRelative 在接口中 cn.taketoday.core.io.Resource
      覆盖:
      createRelative 在类中 cn.taketoday.core.io.AbstractResource
      另请参阅:
      • StringUtils.applyRelativePath(String, String)
    • getName

      @Nullable public String getName()
      This implementation returns the name of the file that this ServletContext resource refers to.
      指定者:
      getName 在接口中 cn.taketoday.core.io.Resource
      覆盖:
      getName 在类中 cn.taketoday.core.io.AbstractResource
      另请参阅:
      • StringUtils.getFilename(String)
    • toString

      public String toString()
      This implementation returns a description that includes the ServletContext resource location.
      指定者:
      toString 在接口中 cn.taketoday.core.io.Resource
      覆盖:
      toString 在类中 cn.taketoday.core.io.AbstractResource
    • getPathWithinContext

      public String getPathWithinContext()
      指定者:
      getPathWithinContext 在接口中 cn.taketoday.core.io.ContextResource
    • equals

      public boolean equals(@Nullable Object other)
      This implementation compares the underlying ServletContext resource locations.
      覆盖:
      equals 在类中 cn.taketoday.core.io.AbstractResource
    • hashCode

      public int hashCode()
      This implementation returns the hash code of the underlying ServletContext resource location.
      覆盖:
      hashCode 在类中 cn.taketoday.core.io.AbstractResource