public class AssetServlet
extends javax.servlet.http.HttpServlet
Constructor and Description |
---|
AssetServlet(String resourcePath,
String uriPath,
String indexFile,
Charset defaultCharset)
Creates a new
AssetServlet that serves static assets loaded from resourceURL
(typically a file: or jar: URL). |
Modifier and Type | Method and Description |
---|---|
protected void |
doGet(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse resp) |
String |
getIndexFile() |
URL |
getResourceURL() |
protected URL |
getResourceUrl(String absoluteRequestedResourcePath) |
String |
getUriPath() |
protected byte[] |
readResource(URL requestedResourceURL) |
doDelete, doHead, doOptions, doPost, doPut, doTrace, getLastModified, service, service
public AssetServlet(String resourcePath, String uriPath, @Nullable String indexFile, @Nullable Charset defaultCharset)
AssetServlet
that serves static assets loaded from resourceURL
(typically a file: or jar: URL). The assets are served at URIs rooted at uriPath
. For
example, given a resourceURL
of "file:/data/assets"
and a uriPath
of
"/js"
, an AssetServlet
would serve the contents of /data/assets/example.js
in response to a request for /js/example.js
. If a directory
is requested and indexFile
is defined, then AssetServlet
will attempt to
serve a file with that name in that directory. If a directory is requested and indexFile
is null, it will serve a 404.resourcePath
- the base URL from which assets are loadeduriPath
- the URI path fragment in which all requests are rootedindexFile
- the filename to use when directories are requested, or null to serve no
indexesdefaultCharset
- the default character setpublic URL getResourceURL()
public String getUriPath()
protected void doGet(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws javax.servlet.ServletException, IOException
doGet
in class javax.servlet.http.HttpServlet
javax.servlet.ServletException
IOException
protected byte[] readResource(URL requestedResourceURL) throws IOException
IOException
Copyright © 2019. All rights reserved.