Ajax / servlet File upload
I'm trying to implement a simple file upload to the server, but i've a little problem.
I've created a web interface with a form where i insert my data, and an input type="file" to select a file from my disk.
When i click on the button to send the request, i set the parameters to be passed via method post, and i do the:
serv.open("POST","myServlet",true); and i send the parameters with serv.send(parameter's list).
In my servlet i save and use them with the request.getParameter("parameterName).
This works rigth if i set the header in this way:
There is a class in java that helps in uploading files, but i've to set the content-type to: multipart/form-data
So i've changed the setRequest in this way:
serv.setRequestHeader('Content-Type', ' multipart/form-data');
But now, in the servlet, i'm not able to take the parametes passed in the serv.send()...i have a null pointer exception.
If i change again the content-type like before, and i try to save the file on server, i have this error:
Posted content type isn't multipart/form-data.
Anybody can help me?