Class StaticResourceServlet

  • All Implemented Interfaces:
    Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig
    Direct Known Subclasses:
    FileSystemResourceServlet

    public abstract class StaticResourceServlet
    extends javax.servlet.http.HttpServlet
    The StaticResourceServlet provides a foundation in which to serve static resources similar to a conventional web server. This class is designed to be extended to provide specific functionality. Adapted from http://stackoverflow.com/questions/132052/servlet-for-serving-static-content
    Since:
    1.2.0
    Author:
    Steve Springett
    See Also:
    Serialized Form
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      protected void doGet​(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)  
      protected void doHead​(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)  
      protected abstract alpine.servlets.StaticResource getStaticResource​(javax.servlet.http.HttpServletRequest request)
      Returns the static resource associated with the given HTTP servlet request.
      • Methods inherited from class javax.servlet.http.HttpServlet

        doDelete, doOptions, doPost, doPut, doTrace, getLastModified, service, service
      • Methods inherited from class javax.servlet.GenericServlet

        destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, init, log, log
    • Constructor Detail

      • StaticResourceServlet

        public StaticResourceServlet()
    • Method Detail

      • doHead

        protected void doHead​(javax.servlet.http.HttpServletRequest request,
                              javax.servlet.http.HttpServletResponse response)
                       throws javax.servlet.ServletException,
                              IOException
        Overrides:
        doHead in class javax.servlet.http.HttpServlet
        Throws:
        javax.servlet.ServletException
        IOException
      • doGet

        protected void doGet​(javax.servlet.http.HttpServletRequest request,
                             javax.servlet.http.HttpServletResponse response)
                      throws javax.servlet.ServletException,
                             IOException
        Overrides:
        doGet in class javax.servlet.http.HttpServlet
        Throws:
        javax.servlet.ServletException
        IOException
      • getStaticResource

        protected abstract alpine.servlets.StaticResource getStaticResource​(javax.servlet.http.HttpServletRequest request)
                                                                     throws IllegalArgumentException
        Returns the static resource associated with the given HTTP servlet request. This returns null when the resource does actually not exist. The servlet will then return a HTTP 404 error.
        Parameters:
        request - The involved HTTP servlet request.
        Returns:
        The static resource associated with the given HTTP servlet request.
        Throws:
        IllegalArgumentException - When the request is mangled in such way that it's not recognizable as a valid static resource request. The servlet will then return a HTTP 400 error.