Package com.ubs.backend.servlets
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
FieldsModifier and TypeFieldDescriptionprivate static floatdefines the max size of a file in MB -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate FileUploadStatuscheckFileStatus(javax.servlet.http.Part filePart, boolean isSupported, boolean fileExists)method to check the status of a fileprotected voiddoGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)Handle Get Request -> Ignore, as Files can't be uploaded using Getprotected voiddoPost(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 Databaseprivate voidhandleResponse(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, serviceMethods inherited from class javax.servlet.GenericServlet
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, init, log, log
-
Field Details
-
MAX_FILESIZE_IN_MB
private static final float MAX_FILESIZE_IN_MBdefines 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:
doGetin classjavax.servlet.http.HttpServlet- Parameters:
request- the HttpRequestresponse- the HttpResponse- Since:
- 17.07.2021
-
doPost
protected void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOExceptionHandle Post Request: - Check if MimeType of file is allowed - Check if Filesize is allowed - Upload File to Database- Overrides:
doPostin classjavax.servlet.http.HttpServlet- Parameters:
request- the HttpRequestresponse- the HttpResponse- Throws:
javax.servlet.ServletException- if there was an error with the execution of the ServletIOException- 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
-