Reusable Java library of general tools with minimal external dependencies.
For questions or support, please contact us:
Email: support@aoindustries.com
Phone: 1-800-519-9541
Phone: +1-251-607-9556
Web: https://www.aoindustries.com/contact
public class LastModifiedServlet extends HttpServlet
When mapped to handle *.css files, parses the underlying file from the file system and automatically adds lastModified=#### URL parameters. This allows the replacement of files to be immediately visible to browsers while still efficiently caching when nothing changed.
The current CSS parser is extremely simple and may not catch all URLs. Specifically, it only looks for URLs on a line-by-line basis and does not support blackslash (\) escapes.
All files must be in the UTF-8 encoding.
This requires the cache be active,
Serialized Form| Modifier and Type | Class and Description |
|---|---|
static class |
LastModifiedServlet.AddLastModifiedWhen |
| Modifier and Type | Field and Description |
|---|---|
static String |
LAST_MODIFIED_HEADER_NAME
The header that may be used to disable automatic lastModified parameters.
|
static String |
LAST_MODIFIED_PARAMETER_NAME
The name of the last modified parameter that is optionally added.
|
| Constructor and Description |
|---|
LastModifiedServlet() |
| Modifier and Type | Method and Description |
|---|---|
static String |
addLastModified(ServletContext servletContext,
HttpServletRequest request,
String servletPath,
String url,
LastModifiedServlet.AddLastModifiedWhen when)
Adds a last modified time (to the nearest second) to a URL if the resource is directly available
as a local resource.
|
protected void |
doGet(HttpServletRequest request,
HttpServletResponse response) |
static String |
encodeLastModified(long lastModified)
Encodes a last modified value.
|
protected long |
getLastModified(HttpServletRequest request) |
static long |
getLastModified(ServletContext servletContext,
HttpServletRequest request,
String path)
Automatically determines extension from path.
|
static long |
getLastModified(ServletContext servletContext,
HttpServletRequest request,
String path,
String extension)
Gets a last modified time given a context-relative path starting with a
slash (/).
|
doDelete, doHead, doOptions, doPost, doPut, doTrace, service, servicedestroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, init, log, logpublic static final String LAST_MODIFIED_PARAMETER_NAME
public static final String LAST_MODIFIED_HEADER_NAME
public static String encodeLastModified(long lastModified)
public static long getLastModified(ServletContext servletContext, HttpServletRequest request, String path, String extension)
Gets a last modified time given a context-relative path starting with a slash (/).
Any file ending in ".css" (case-insensitive) will be parsed and will have a modified time that is equal to the greatest of itself or any referenced URL.
0 when unknown.public static long getLastModified(ServletContext servletContext, HttpServletRequest request, String path)
#getLastModified(javax.servlet.ServletContext, java.lang.String, java.lang.String)public static String addLastModified(ServletContext servletContext, HttpServletRequest request, String servletPath, String url, LastModifiedServlet.AddLastModifiedWhen when) throws MalformedURLException
Adds a last modified time (to the nearest second) to a URL if the resource is directly available as a local resource. Only applies to relative URLs (./, ../) or URLs that begin with a slash (/).
This implementation assume anchors (#) are always after the last question mark (?).
MalformedURLExceptionprotected long getLastModified(HttpServletRequest request)
getLastModified in class HttpServletprotected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
doGet in class HttpServletServletExceptionIOExceptionCopyright © 2000–2016 AO Industries, Inc.. All rights reserved.