I am trying to submit a form using the post method and a FormData object. I annotated my servlet with @MultipartConfig but it doesnt work
js
async function addAuthors() {
let xhr = new XMLHttpRequest();
const form = document.getElementById( "authorForm" );
const FD = new FormData(form);
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhr.open("POST", "http://localhost:8081/Task1_war/main?command=addAuthor");
xhr.send(FD);
}
html
<form id="authorForm">
<Label>Author (required)</Label>
<input type="text" name="authorName" class="req"/>
<label class="errorInput" ></label>
<Label>Author image></Label>
<input type="file" id="authorImage" name="path" accept=".jpg,.png,.jpeg ">
</form>
<div class="add" onclick="addAuthors()">Send</div>