java.lang.Object | ||||
↳ | org.springframework.context.support.ApplicationObjectSupport | |||
↳ | org.springframework.web.context.support.WebApplicationObjectSupport | |||
↳ | org.springframework.web.servlet.support.WebContentGenerator | |||
↳ | org.springframework.web.servlet.resource.ResourceHttpRequestHandler |
HttpRequestHandler
that serves static resources optimized for superior browser performance
(according to the guidelines of Page Speed, YSlow, etc.) by allowing for flexible cache settings
("cacheSeconds" property
, last-modified support).
The "locations" property
takes a list of Spring Resource
locations
from which static resources are allowed to be served by this handler. For a given request, the
list of locations will be consulted in order for the presence of the requested resource, and the
first found match will be written to the response, with Expires
and Cache-Control
headers set as configured. The handler also properly evaluates the Last-Modified
header
(if present) so that a 304
status code will be returned as appropriate, avoiding unnecessary
overhead for resources that are already cached by the client. The use of Resource
locations
allows resource requests to easily be mapped to locations other than the web application root. For
example, resources could be served from a classpath location such as "classpath:/META-INF/public-web-resources/",
allowing convenient packaging and serving of resources such as a JavaScript library from within jar files.
To ensure that users with a primed browser cache get the latest changes to application-specific resources upon deployment of new versions of the application, it is recommended that a version string is used in the URL mapping pattern that selects this handler. Such patterns can be easily parameterized using Spring EL. See the reference manual for further examples of this approach.
Rather than being directly configured as a bean, this handler will typically be configured
through use of the <mvc:resources/>
XML configuration element.
[Expand]
Inherited Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
org.springframework.web.servlet.support.WebContentGenerator
|
[Expand]
Inherited Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
org.springframework.context.support.ApplicationObjectSupport
|
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Processes a resource request.
| |||||||||||
Set a
List of Resource paths to use as sources
for serving static resources. |
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Determine an appropriate media type for the given resource.
| |||||||||||
Set headers on the given servlet response.
| |||||||||||
Write the actual content out to the given servlet response,
streaming the resource's content.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
org.springframework.web.servlet.support.WebContentGenerator
| |||||||||||
From class
org.springframework.web.context.support.WebApplicationObjectSupport
| |||||||||||
From class
org.springframework.context.support.ApplicationObjectSupport
| |||||||||||
From class
java.lang.Object
| |||||||||||
From interface
org.springframework.context.ApplicationContextAware
| |||||||||||
From interface
org.springframework.web.HttpRequestHandler
| |||||||||||
From interface
org.springframework.web.context.ServletContextAware
|
Processes a resource request.
Checks for the existence of the requested resource in the configured list of locations.
If the resource does not exist, a 404
response will be returned to the client.
If the resource exists, the request will be checked for the presence of the
Last-Modified
header, and its value will be compared against the last-modified
timestamp of the given resource, returning a 304
status code if the
Last-Modified
value is greater. If the resource is newer than the
Last-Modified
value, or the header is not present, the content resource
of the resource will be written to the response with caching headers
set to expire one year in the future.
request | current HTTP request |
---|---|
response | current HTTP response |
IOException | |
---|---|
ServletException |
Set a List
of Resource
paths to use as sources
for serving static resources.
Determine an appropriate media type for the given resource.
resource | the resource to check |
---|
null
if none found
Set headers on the given servlet response. Called for GET requests as well as HEAD requests.
response | current servlet response |
---|---|
resource | the identified resource (never null ) |
mediaType | the resource's media type (never null ) |
IOException | in case of errors while setting the headers |
---|
Write the actual content out to the given servlet response, streaming the resource's content.
response | current servlet response |
---|---|
resource | the identified resource (never null ) |
IOException | in case of errors while writing the content |
---|