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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voiddoGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) protected voiddoPost(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) File uploadin from file item componentstatic voiddownloadFile(UI ui, JBFile file) Downloads the file specified by aJBFileobject to the UI.static voiddownloadFile(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, serviceMethods 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:
doGetin 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:
doPostin classjavax.servlet.http.HttpServlet- Throws:
javax.servlet.ServletExceptionIOException
-
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 aJBFileobject to the UI.- Parameters:
ui- UI instancefile- TheJBFileobject representing the file- Throws:
NullPointerException- Thrown if:
-