Class AssetServlet

  • All Implemented Interfaces:
    Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig

    public class AssetServlet
    extends javax.servlet.http.HttpServlet
    See Also:
    Serialized Form
    • Constructor Detail

      • 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
    • Method Detail

      • getResourceURL

        public URL getResourceURL()
      • getUriPath

        public String getUriPath()
      • getIndexFile

        @Nullable
        public String getIndexFile()
      • doGet

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

        protected URL getResourceUrl​(String absoluteRequestedResourcePath)