I am trying to develop a webpage that enables users to upload one or more files to a servlet without the need for a form submission.
I am open to utilizing jQuery and/or Ajax for this purpose and prefer not to rely on any other third-party libraries.
I currently have a servlet that functions with a form submission and I am willing to make necessary adjustments to make it work without the form submission:
package ajaxdemo;
// Java code for file upload Servlet
The code above functions with a specific input form which I'm looking to adapt for use without the form submission:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<!-- HTML code for file upload form -->
In my attempt to make it work without form submission, I've created the following page:
<html>
<!-- HTML code for file upload popup dialog -->
During testing, I encountered an error message from the server (shown in the eclipse console) stating that no multipart boundary was found.
If I remove the JavaScript line setting the request header, the error message changes to indicate that filePart
is null, preventing the invocation of getSubmittedFileName()
.
I explored an alternative method using await fetch(...)
instead of xmlRequest.send(...)
, but encountered difficulty in getting it to function correctly.
Ultimately, I aim to enable users to upload multiple files and receive a JSON structure in return for displaying a table. However, I am currently focused on resolving the issue with the initial file upload.