Class FileSystemResourceServlet

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

    public class FileSystemResourceServlet
    extends StaticResourceServlet
    The FileSystemResourceServlet serves StaticResources from the file system similar to a conventional web server. Adapted from http://stackoverflow.com/questions/132052/servlet-for-serving-static-content The Servlet contains two parameters, directory and absolute. The directory specifies the the absolute or relative directory in which to serve files from. If the absolute parameter is false (or not specified), then the directory will be relative from the context of the webapp. Sample usage:
     <servlet>
         <servlet-name>My Images</servlet-name>
         <servlet-class>alpine.servlets.FileSystemResourceServlet</servlet-class>
         <init-param>
             <param-name>directory</param-name>
             <param-value>/path/to/images</param-value>
         </init-param>
         <init-param>
             <param-name>absolute</param-name>
             <param-value>true</param-value>
         </init-param>
         <load-on-startup>1</load-on-startup>
     </servlet>
     <servlet-mapping>
         <servlet-name>My Images</servlet-name>
         <url-pattern>/images/*</url-pattern>
     </servlet-mapping>
     
    Since:
    1.2.0
    Author:
    Steve Springett
    See Also:
    Serialized Form
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected alpine.servlets.StaticResource getStaticResource​(javax.servlet.http.HttpServletRequest request)
      Returns the static resource associated with the given HTTP servlet request.
      void init​(javax.servlet.ServletConfig config)
      Overrides the servlet init method and loads sets the InputStream necessary to load application.properties.
      void setAbsolute​(boolean absolute)  
      void setDirectory​(String directory)  
      • 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, log, log
    • Constructor Detail

      • FileSystemResourceServlet

        public FileSystemResourceServlet()
    • Method Detail

      • init

        public void init​(javax.servlet.ServletConfig config)
                  throws javax.servlet.ServletException
        Overrides the servlet init method and loads sets the InputStream necessary to load application.properties.
        Specified by:
        init in interface javax.servlet.Servlet
        Overrides:
        init in class javax.servlet.GenericServlet
        Throws:
        javax.servlet.ServletException - a general error that occurs during initialization
      • getStaticResource

        protected alpine.servlets.StaticResource getStaticResource​(javax.servlet.http.HttpServletRequest request)
                                                            throws IllegalArgumentException
        Description copied from class: StaticResourceServlet
        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.
        Specified by:
        getStaticResource in class StaticResourceServlet
        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.
      • setDirectory

        public void setDirectory​(String directory)
      • setAbsolute

        public void setAbsolute​(boolean absolute)