Package alpine.server.servlets
Class FileSystemResourceServlet
java.lang.Object
javax.servlet.GenericServlet
javax.servlet.http.HttpServlet
alpine.server.servlets.StaticResourceServlet
alpine.server.servlets.FileSystemResourceServlet
- All Implemented Interfaces:
Serializable,javax.servlet.Servlet,javax.servlet.ServletConfig
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:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected alpine.server.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.server.servlets.StaticResourceServlet
doGet, doHeadMethods inherited from class javax.servlet.http.HttpServlet
doDelete, doOptions, doPost, doPut, doTrace, getLastModified, service, serviceMethods inherited from class javax.servlet.GenericServlet
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log
-
Constructor Details
-
FileSystemResourceServlet
public FileSystemResourceServlet()
-
-
Method Details
-
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:
initin interfacejavax.servlet.Servlet- Overrides:
initin classjavax.servlet.GenericServlet- Throws:
javax.servlet.ServletException- a general error that occurs during initialization
-
getStaticResource
protected alpine.server.servlets.StaticResource getStaticResource(javax.servlet.http.HttpServletRequest request) throws IllegalArgumentException Description 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
-
setAbsolute
public void setAbsolute(boolean absolute)
-