Results 1 to 1 of 1
Thread: Ajax / servlet File upload
- 06-08-2010, 02:48 PM #1Member
- Join Date
- Jun 2010
- Rep Power
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?
- By tommy_725 in forum NetworkingReplies: 0Last Post: 10-16-2009, 12:21 AM
- By amit_m04 in forum Java ServletReplies: 1Last Post: 09-27-2009, 03:06 AM
- By hofsoc in forum Advanced JavaReplies: 6Last Post: 06-04-2009, 11:09 PM
- By jeniramires in forum Advanced JavaReplies: 3Last Post: 08-18-2008, 07:34 PM
- By simon in forum Java ServletReplies: 1Last Post: 08-05-2007, 03:50 AM