Package alpine.servlets
Class FileSystemResourceServlet
- java.lang.Object
-
- javax.servlet.GenericServlet
-
- javax.servlet.http.HttpServlet
-
- alpine.servlets.StaticResourceServlet
-
- alpine.servlets.FileSystemResourceServlet
-
- All Implemented Interfaces:
Serializable,javax.servlet.Servlet,javax.servlet.ServletConfig
public class FileSystemResourceServlet extends StaticResourceServlet
The FileSystemResourceServlet servesStaticResources 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
-
-
Constructor Summary
Constructors Constructor Description FileSystemResourceServlet()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected alpine.servlets.StaticResourcegetStaticResource(javax.servlet.http.HttpServletRequest request)Returns the static resource associated with the given HTTP servlet request.voidinit(javax.servlet.ServletConfig config)Overrides the servlet init method and loads sets the InputStream necessary to load application.properties.voidsetAbsolute(boolean absolute)voidsetDirectory(String directory)-
Methods inherited from class alpine.servlets.StaticResourceServlet
doGet, doHead
-
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doOptions, doPost, doPut, doTrace, getLastModified, service, service
-
-
-
-
Method Detail
-
init
public void init(javax.servlet.ServletConfig config) throws javax.servlet.ServletExceptionOverrides the servlet init method and loads sets the InputStream necessary to load application.properties.- Specified by:
initin interfacejavax.servlet.Servlet- Overrides:
initin classjavax.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 IllegalArgumentExceptionDescription copied from class:StaticResourceServletReturns the static resource associated with the given HTTP servlet request. This returnsnullwhen the resource does actually not exist. The servlet will then return a HTTP 404 error.- Specified by:
getStaticResourcein classStaticResourceServlet- 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)
-
-