Class StaticResourceServlet

java.lang.Object
javax.servlet.GenericServlet
javax.servlet.http.HttpServlet
alpine.server.servlets.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:
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    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.server.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

    Methods inherited from class java.lang.Object

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

    • StaticResourceServlet

      public StaticResourceServlet()
  • Method Details

    • 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.server.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.