Class FileManagerServlet
- All Implemented Interfaces:
Serializable
,javax.servlet.Servlet
,javax.servlet.ServletConfig
File manager servlet.
Files to be downloaded are stored in a temporary cache.
An item in the cache is a file, designated with a unique ID.
A file is stored in the cache for the time period specified by the parameter JBStrapParamType.DOWNLOAD_LINK_EXPIRATION_TIME
.
If the file is downloaded or the time expires, the file is removed from the cache and will not be available for download.
If you want to download a file, it is saved to the cache. A JavaScript method call originating from the interface causes the servlet to start file download. The method call is a GET method and you pass the file ID as a parameter to the method. The servlet gets the reference file from the cache and all its metadata and downloads it to the client. The file download request is given an OCTET stream response.
If the file download is impossible (due to the file not being in the cache or an error occurred during file download), the servlet sends a PLAIN/TEXT response with the error text.
- Since:
- 4.0
- Author:
- JBStrap
- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
doGet
(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) protected void
doPost
(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) File uploadin from file item componentstatic void
downloadFile
(UI ui, JBFile file) Downloads the file specified by aJBFile
object to the UI.static void
downloadFile
(UI ui, String filename, byte[] fileBody) Downloads the file to the specified UI.Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doHead, doOptions, doPut, doTrace, getLastModified, service, service
Methods inherited from class javax.servlet.GenericServlet
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, init, log, log
-
Constructor Details
-
FileManagerServlet
public FileManagerServlet()
-
-
Method Details
-
doGet
protected void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) - Overrides:
doGet
in classjavax.servlet.http.HttpServlet
- Parameters:
request
- Client request containing file ID in the “id” parameterresponse
- Response to the request, either an OCTET stream or PLAIN/TEXT
-
doPost
protected void doPost(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws javax.servlet.ServletException, IOException File uploadin from file item component- Overrides:
doPost
in classjavax.servlet.http.HttpServlet
- Throws:
javax.servlet.ServletException
IOException
-
downloadFile
Downloads the file to the specified UI.- Parameters:
ui
- UI instancefilename
- File namefileBody
- File content as a byte array- Throws:
NullPointerException
- Thrown if the specified file name or UI isnull
-
downloadFile
Downloads the file specified by aJBFile
object to the UI.- Parameters:
ui
- UI instancefile
- TheJBFile
object representing the file- Throws:
NullPointerException
- Thrown if:
-