| Author |
Submit multipart and form data
|
Justin Howard
Ranch Hand
Joined: Feb 19, 2009
Posts: 162
|
|
Hi All,
When I submit multipart content with the form data , it does not seem to recognize
the form data. I am trying to upload the file using jquery file upload scripts, is there any other way I can
handle it ?
Thanks
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56529
|
|
When you submit a multi-part form, the request's getParameter() family of methods cannot parse the data (it's in the wrong format). Rather, the file upload library you are using should have an API to make the values available. If you are parsing the request data yourself, instead of using a file upload library, you need to do it yourself.
See the JSP FAQ for more info.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Justin Howard
Ranch Hand
Joined: Feb 19, 2009
Posts: 162
|
|
Thanks for the reply.
I tried using org.apache.commons.fileupload.* file upload library.
But still i am not able to retrieve the form values.
How can I parse the values myself?
Thanks
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56529
|
|
Justin Howard wrote:
I tried using org.apache.commons.fileupload.* file upload library.
But still i am not able to retrieve the form values.
Why not?
How can I parse the values myself?
You can't. The library has already read the stream. Answering the above question is more important than finding work-arounds.
|
 |
Justin Howard
Ranch Hand
Joined: Feb 19, 2009
Posts: 162
|
|
When the form gets submit this is the code I have in the servlet.
But I everytime I submit the value of ccMails is null. ccMails is the example I gave, all the other form values are null as well.
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56529
|
|
|
As I have already explained, getParameter() will not work. You need to use the API provided by the upload library.
|
 |
Justin Howard
Ranch Hand
Joined: Feb 19, 2009
Posts: 162
|
|
You were absolutely correct. I changed the code to reflect the new apis.
However now, for the file content it gives me an exception.
If I cast it (((FileItem) item).write(uploadedFile);) gives me an exception if I dont it gives an error.
Exception: org.apache.commons.fileupload.FileUploadBase$FileItemIteratorImpl$FileItemStreamImpl cannot be cast
Thanks
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16487
|
|
I haven't looked at the API documentation myself, but I see you create a FileItemFactory and then don't do anything with it. Shouldn't you use that to create a FileItem object?
I'm not surprised you can't cast a FileItemStream object to a FileItem variable, just based on the names of the types.
|
 |
 |
|
|
subject: Submit multipart and form data
|
|
|