Class FileUpload

java.lang.Object
javax.servlet.GenericServlet
javax.servlet.http.HttpServlet
com.ubs.backend.servlets.FileUpload
All Implemented Interfaces:
Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig

@WebServlet(name="FileUpload", value="/FileUpload") public class FileUpload extends javax.servlet.http.HttpServlet
Servlet to Upload a File to the Database
Since:
17.07.2021
Author:
Marc
See Also:
Serialized Form
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static float
    defines the max size of a file in MB
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    checkFileStatus​(javax.servlet.http.Part filePart, boolean isSupported, boolean fileExists)
    method to check the status of a file
    protected void
    doGet​(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
    Handle Get Request -> Ignore, as Files can't be uploaded using Get
    protected void
    doPost​(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
    Handle Post Request: - Check if MimeType of file is allowed - Check if Filesize is allowed - Upload File to Database
    private void
    handleResponse​(javax.servlet.http.HttpServletResponse response, FileUploadStatus status, UploadFile file, UploadFileDAO fileDAO)
     

    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
  • Field Details

    • MAX_FILESIZE_IN_MB

      private static final float MAX_FILESIZE_IN_MB
      defines the max size of a file in MB
      Since:
      17.07.2021
      See Also:
      Constant Field Values
  • Constructor Details

    • FileUpload

      public FileUpload()
  • Method Details

    • doGet

      protected void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
      Handle Get Request -> Ignore, as Files can't be uploaded using Get
      Overrides:
      doGet in class javax.servlet.http.HttpServlet
      Parameters:
      request - the HttpRequest
      response - the HttpResponse
      Since:
      17.07.2021
    • doPost

      protected void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException
      Handle Post Request: - Check if MimeType of file is allowed - Check if Filesize is allowed - Upload File to Database
      Overrides:
      doPost in class javax.servlet.http.HttpServlet
      Parameters:
      request - the HttpRequest
      response - the HttpResponse
      Throws:
      javax.servlet.ServletException - if there was an error with the execution of the Servlet
      IOException - if File couldn't be uploaded
      Since:
      17.07.2021
    • handleResponse

      private void handleResponse(javax.servlet.http.HttpServletResponse response, FileUploadStatus status, UploadFile file, UploadFileDAO fileDAO) throws IOException
      Parameters:
      response -
      status -
      file -
      fileDAO -
      Throws:
      IOException
      Since:
      17.07.2021
    • checkFileStatus

      private FileUploadStatus checkFileStatus(javax.servlet.http.Part filePart, boolean isSupported, boolean fileExists)
      method to check the status of a file
      Parameters:
      filePart -
      isSupported -
      fileExists -
      Returns:
      Since:
      19.07.2021