Class FileManagerServlet

java.lang.Object
javax.servlet.GenericServlet
javax.servlet.http.HttpServlet
com.jbstrap.ui.servlet.FileManagerServlet
All Implemented Interfaces:
Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig

@WebServlet("/fileManager/*") public class FileManagerServlet extends javax.servlet.http.HttpServlet

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
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected 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 component
    static void
    downloadFile(UI ui, JBFile file)
    Downloads the file specified by a JBFile 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

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • FileManagerServlet

      public FileManagerServlet()
  • Method Details

    • doGet

      protected void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
      Overrides:
      doGet in class javax.servlet.http.HttpServlet
      Parameters:
      request - Client request containing file ID in the “id” parameter
      response - 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 class javax.servlet.http.HttpServlet
      Throws:
      javax.servlet.ServletException
      IOException
    • downloadFile

      public static void downloadFile(UI ui, String filename, byte[] fileBody)
      Downloads the file to the specified UI.
      Parameters:
      ui - UI instance
      filename - File name
      fileBody - File content as a byte array
      Throws:
      NullPointerException - Thrown if the specified file name or UI is null
    • downloadFile

      public static void downloadFile(UI ui, JBFile file)
      Downloads the file specified by a JBFile object to the UI.
      Parameters:
      ui - UI instance
      file - The JBFile object representing the file
      Throws:
      NullPointerException - Thrown if:
      • The specified JBFile object is null
      • The specified JBFile object does not contain a file name
      • The specified JBFile object does not contain a file
      • The specified UI is null