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

    Constructors
    Constructor
    Description
    AssetServlet(String resourcePath, String uriPath, @Nullable String indexFile, @Nullable String defaultMediaType, @Nullable Charset defaultCharset)
    Creates a new AssetServlet that serves static assets loaded from resourceURL (typically a file: or jar: URL).
    AssetServlet(String resourcePath, String uriPath, @Nullable String indexFile, @Nullable Charset defaultCharset)
    Creates a new AssetServlet that serves static assets loaded from resourceURL (typically a file: or jar: URL).
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    doGet(jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse resp)
     
    @Nullable Charset
     
     
    @Nullable String
     
     
    protected URL
    getResourceURL(String absoluteRequestedResourcePath)
     
     
    protected byte[]
    readResource(URL requestedResourceURL)
     

    Methods inherited from class jakarta.servlet.http.HttpServlet

    doDelete, doHead, doOptions, doPost, doPut, doTrace, getLastModified, init, service, service

    Methods inherited from class jakarta.servlet.GenericServlet

    destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • AssetServlet

      public AssetServlet(String resourcePath, String uriPath, @Nullable String indexFile, @Nullable Charset defaultCharset)
      Creates a new 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.
      Parameters:
      resourcePath - the base URL from which assets are loaded
      uriPath - the URI path fragment in which all requests are rooted
      indexFile - the filename to use when directories are requested, or null to serve no indexes
      defaultCharset - the default character set
    • AssetServlet

      public AssetServlet(String resourcePath, String uriPath, @Nullable String indexFile, @Nullable String defaultMediaType, @Nullable Charset defaultCharset)
      Creates a new 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.
      Parameters:
      resourcePath - the base URL from which assets are loaded
      uriPath - the URI path fragment in which all requests are rooted
      indexFile - the filename to use when directories are requested, or null to serve no indexes
      defaultMediaType - the default media type
      defaultCharset - the default character set
      Since:
      2.0
  • Method Details

    • getResourceURL

      public URL getResourceURL()
    • getUriPath

      public String getUriPath()
    • getIndexFile

      public @Nullable String getIndexFile()
    • getDefaultMediaType

      public String getDefaultMediaType()
      Since:
      2.0
    • getDefaultCharset

      public @Nullable Charset getDefaultCharset()
      Since:
      2.0
    • doGet

      protected void doGet(jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse resp) throws jakarta.servlet.ServletException, IOException
      Overrides:
      doGet in class jakarta.servlet.http.HttpServlet
      Throws:
      jakarta.servlet.ServletException
      IOException
    • getResourceURL

      protected URL getResourceURL(String absoluteRequestedResourcePath)
    • readResource

      protected byte[] readResource(URL requestedResourceURL) throws IOException
      Throws:
      IOException