类 ServletContextResource
- java.lang.Object
- org.springframework.core.io.AbstractResource
- org.springframework.core.io.AbstractFileResolvingResource
- org.springframework.web.context.support.ServletContextResource
- 所有已实现的接口:
ContextResource
,InputStreamSource
,Resource
public class ServletContextResource extends AbstractFileResolvingResource implements ContextResource
Resource
implementation forServletContext
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.- 从以下版本开始:
- 28.12.2003
- 作者:
- Juergen Hoeller
- 另请参阅:
ServletContext.getResourceAsStream(java.lang.String)
,ServletContext.getResource(java.lang.String)
,ServletContext.getRealPath(java.lang.String)
构造器概要
构造器 构造器 说明 ServletContextResource(ServletContext servletContext, String path)
Create a new ServletContextResource.
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 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 obj)
This implementation compares the underlying ServletContext resource locations.boolean
exists()
This implementation checksServletContext.getResource
.String
getDescription()
This implementation returns a description that includes the ServletContext resource location.File
getFile()
This implementation resolves "file:" URLs or alternatively delegates toServletContext.getRealPath
, throwing a FileNotFoundException if not found or not resolvable.String
getFilename()
This implementation returns the name of the file that this ServletContext resource refers to.InputStream
getInputStream()
This implementation delegates toServletContext.getResourceAsStream
, but throws a FileNotFoundException if no resource found.String
getPath()
Return the path for this resource.String
getPathWithinContext()
Return the path within the enclosing 'context'.ServletContext
getServletContext()
Return the ServletContext for this resource.URL
getURL()
This implementation delegates toServletContext.getResource
, but throws a FileNotFoundException if no resource found.int
hashCode()
This implementation returns the hash code of the underlying ServletContext resource location.boolean
isReadable()
This implementation delegates toServletContext.getResourceAsStream
, which returnsnull
in case of a non-readable resource (e.g. a directory).从类继承的方法 org.springframework.core.io.AbstractFileResolvingResource
contentLength, customizeConnection, customizeConnection, getFile, getFileForLastModifiedCheck, lastModified
从类继承的方法 org.springframework.core.io.AbstractResource
getURI, isOpen, toString
从接口继承的方法 org.springframework.core.io.Resource
contentLength, getURI, isOpen, lastModified
构造器详细资料
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 frompath
- the path of the resource
方法详细资料
getServletContext
public final ServletContext getServletContext()
Return the ServletContext for this resource.
exists
public boolean exists()
This implementation checksServletContext.getResource
.- 指定者:
exists
在接口中Resource
- 覆盖:
exists
在类中AbstractFileResolvingResource
- 另请参阅:
ServletContext.getResource(String)
isReadable
public boolean isReadable()
This implementation delegates toServletContext.getResourceAsStream
, which returnsnull
in case of a non-readable resource (e.g. a directory).
getInputStream
public InputStream getInputStream() throws IOException
This implementation delegates toServletContext.getResourceAsStream
, but throws a FileNotFoundException if no resource found.- 指定者:
getInputStream
在接口中InputStreamSource
- 返回:
- the input stream for the underlying resource (must not be
null
) - 抛出:
FileNotFoundException
- if the underlying resource doesn't existIOException
- if the content stream could not be opened- 另请参阅:
ServletContext.getResourceAsStream(String)
getURL
public URL getURL() throws IOException
This implementation delegates toServletContext.getResource
, but throws a FileNotFoundException if no resource found.- 指定者:
getURL
在接口中Resource
- 覆盖:
getURL
在类中AbstractResource
- 抛出:
IOException
- if the resource cannot be resolved as URL, i.e. if the resource is not available as descriptor- 另请参阅:
ServletContext.getResource(String)
getFile
public File getFile() throws IOException
This implementation resolves "file:" URLs or alternatively delegates toServletContext.getRealPath
, throwing a FileNotFoundException if not found or not resolvable.- 指定者:
getFile
在接口中Resource
- 覆盖:
getFile
在类中AbstractFileResolvingResource
- 抛出:
FileNotFoundException
- if the resource cannot be resolved as absolute file path, i.e. if the resource is not available in a file systemIOException
- in case of general resolution/reading failures- 另请参阅:
ServletContext.getResource(String)
,ServletContext.getRealPath(String)
createRelative
public 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
在接口中Resource
- 覆盖:
createRelative
在类中AbstractResource
- 参数:
relativePath
- the relative path (relative to this resource)- 返回:
- the resource handle for the relative resource
- 另请参阅:
StringUtils.applyRelativePath(String, String)
getFilename
public String getFilename()
This implementation returns the name of the file that this ServletContext resource refers to.- 指定者:
getFilename
在接口中Resource
- 覆盖:
getFilename
在类中AbstractResource
- 另请参阅:
StringUtils.getFilename(String)
getDescription
public String getDescription()
This implementation returns a description that includes the ServletContext resource location.- 指定者:
getDescription
在接口中Resource
- 另请参阅:
Object.toString()
getPathWithinContext
public String getPathWithinContext()
从接口复制的说明:ContextResource
Return the path within the enclosing 'context'.This is typically path relative to a context-specific root directory, e.g. a ServletContext root or a PortletContext root.
- 指定者:
getPathWithinContext
在接口中ContextResource
equals
public boolean equals(Object obj)
This implementation compares the underlying ServletContext resource locations.- 覆盖:
equals
在类中AbstractResource
- 另请参阅:
Resource.getDescription()
hashCode
public int hashCode()
This implementation returns the hash code of the underlying ServletContext resource location.- 覆盖:
hashCode
在类中AbstractResource
- 另请参阅:
Resource.getDescription()