Package alpine.server.servlets
Class StaticResourceServlet
java.lang.Object
jakarta.servlet.GenericServlet
jakarta.servlet.http.HttpServlet
alpine.server.servlets.StaticResourceServlet
- All Implemented Interfaces:
jakarta.servlet.Servlet,jakarta.servlet.ServletConfig,Serializable
- Direct Known Subclasses:
FileSystemResourceServlet
public abstract class StaticResourceServlet
extends jakarta.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:
-
Field Summary
Fields inherited from class jakarta.servlet.http.HttpServlet
LEGACY_DO_HEAD -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voiddoGet(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) protected voiddoHead(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) protected abstract alpine.server.servlets.StaticResourcegetStaticResource(jakarta.servlet.http.HttpServletRequest request) Returns the static resource associated with the given HTTP servlet request.Methods inherited from class jakarta.servlet.http.HttpServlet
doDelete, doOptions, doPatch, doPost, doPut, doTrace, getLastModified, init, isSensitiveHeader, service, serviceMethods inherited from class jakarta.servlet.GenericServlet
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log
-
Constructor Details
-
StaticResourceServlet
public StaticResourceServlet()
-
-
Method Details
-
doHead
protected void doHead(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) throws jakarta.servlet.ServletException, IOException - Overrides:
doHeadin classjakarta.servlet.http.HttpServlet- Throws:
jakarta.servlet.ServletExceptionIOException
-
doGet
protected void doGet(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) throws jakarta.servlet.ServletException, IOException - Overrides:
doGetin classjakarta.servlet.http.HttpServlet- Throws:
jakarta.servlet.ServletExceptionIOException
-
getStaticResource
protected abstract alpine.server.servlets.StaticResource getStaticResource(jakarta.servlet.http.HttpServletRequest request) throws IllegalArgumentException Returns 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.- 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.
-