This is my first time trying to use XMLHttpRequest (to upload a file dragged on to a web page) and I can't get it to do anything. I have the following Javascript code in my web page:
function upload(file)
{
var formData = new FormData();
formData.append("file", file);
var xhr = new XMLHttpRequest();
xhr.open("POST", "servlet/UploadServlet", false);
xhr.send(formData);
}
I placed my servlet class UploadServlet
and my web page within the "examples" directory structure of my Tomcat server. But while I'm able to execute the HelloWordServlet
example via a link on my page, I'm unable to get the XmlHttpRequest.send() to do anything. But I have been able to verifry that the Javascript code prior to that line is working, i.e., the file passed into the routine was successfully appended to the FormData object. A look into the server logs revealed nothing, and there wasn't anything when I brought up the console log either. What am I doing wrong?
As it turns out, the problem wasn't with XmlHttpRequest, but with the servlet itself: I hadn't added it to the relevant mappings in web.xml