- All Implemented Interfaces:
- Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig
public class DownloadServlet
extends javax.servlet.http.HttpServlet
Servlet for downloading a HttpResource (e.g. a file) given some path. Operates using the following steps.
Step (1), determine the path:
- Instance variable pathGetter is set: If the request parameter jobId is set, pass its value, or otherwise
the result of calling request.getPathInfo() to the pathGetter. Proceed with the path it returns.
- Otherwise: Proceed with the path request.getPathInfo() returns.
In both cases, the path is still one that uses "/" as separator character.
Step (2), determine the ContentType based on the suffix after the last dot "." in the path.
Step (3), determine the Content-Disposition. The filename used for that (i.e. the filename presented to the
user) is (a) the value of the request parameter "fileName" if set, or otherwise (b) the suffix after the last "/"
of the path.
Step (4), get the desired resource using the configured HttpResourceResolver.
Usecases when a pathGetter needs to be used are e.g., if the file is the result of some job, i.e., needs to be queried
by job id first, or generally if the path passed to the servlet does not contain the whole file name.
In both cases, determining the ContentType and Content-Disposition would not be possible if the HttpResourceResolver would
do all the job, as the latter just returns a HttpResource given a pathInfo. I.e. if the path is transformed inside the
HttpResourceResolver, we don“t have any chance to inspect it in order to derive ContentType and Content-Disposition based
on it.
- See Also:
- Serialized Form