Package io.dropwizard.servlets.assets
Class AssetServlet
java.lang.Object
jakarta.servlet.GenericServlet
jakarta.servlet.http.HttpServlet
io.dropwizard.servlets.assets.AssetServlet
- All Implemented Interfaces:
jakarta.servlet.Servlet,jakarta.servlet.ServletConfig,Serializable
public class AssetServlet
extends jakarta.servlet.http.HttpServlet
- See Also:
-
Field Summary
Fields inherited from class jakarta.servlet.http.HttpServlet
LEGACY_DO_HEAD -
Constructor Summary
ConstructorsConstructorDescriptionAssetServlet(String resourcePath, String uriPath, @Nullable String indexFile, @Nullable String defaultMediaType, @Nullable Charset defaultCharset) Creates a newAssetServletthat serves static assets loaded fromresourceURL(typically a file: or jar: URL).AssetServlet(String resourcePath, String uriPath, @Nullable String indexFile, @Nullable Charset defaultCharset) Creates a newAssetServletthat serves static assets loaded fromresourceURL(typically a file: or jar: URL). -
Method Summary
Modifier and TypeMethodDescriptionprotected voiddoGet(jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse resp) @Nullable Charset@Nullable Stringprotected URLgetResourceURL(String absoluteRequestedResourcePath) protected byte[]readResource(URL requestedResourceURL) Methods inherited from class jakarta.servlet.http.HttpServlet
doDelete, doHead, doOptions, doPost, doPut, doTrace, getLastModified, init, service, serviceMethods inherited from class jakarta.servlet.GenericServlet
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log
-
Constructor Details
-
AssetServlet
public AssetServlet(String resourcePath, String uriPath, @Nullable String indexFile, @Nullable Charset defaultCharset) Creates a newAssetServletthat serves static assets loaded fromresourceURL(typically a file: or jar: URL). The assets are served at URIs rooted aturiPath. For example, given aresourceURLof"file:/data/assets"and auriPathof"/js", anAssetServletwould serve the contents of/data/assets/example.jsin response to a request for/js/example.js. If a directory is requested andindexFileis defined, thenAssetServletwill attempt to serve a file with that name in that directory. If a directory is requested andindexFileis null, it will serve a 404.- Parameters:
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 set
-
AssetServlet
public AssetServlet(String resourcePath, String uriPath, @Nullable String indexFile, @Nullable String defaultMediaType, @Nullable Charset defaultCharset) Creates a newAssetServletthat serves static assets loaded fromresourceURL(typically a file: or jar: URL). The assets are served at URIs rooted aturiPath. For example, given aresourceURLof"file:/data/assets"and auriPathof"/js", anAssetServletwould serve the contents of/data/assets/example.jsin response to a request for/js/example.js. If a directory is requested andindexFileis defined, thenAssetServletwill attempt to serve a file with that name in that directory. If a directory is requested andindexFileis null, it will serve a 404.- Parameters:
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 indexesdefaultMediaType- the default media typedefaultCharset- the default character set- Since:
- 2.0
-
-
Method Details
-
getResourceURL
-
getUriPath
-
getIndexFile
-
getDefaultMediaType
- Since:
- 2.0
-
getDefaultCharset
- Since:
- 2.0
-
doGet
protected void doGet(jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse resp) throws jakarta.servlet.ServletException, IOException - Overrides:
doGetin classjakarta.servlet.http.HttpServlet- Throws:
jakarta.servlet.ServletExceptionIOException
-
getResourceURL
-
readResource
- Throws:
IOException
-