Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Submit multipart and form data

 
Justin Howard
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64982
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Justin Howard
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64982
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64982
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As I have already explained, getParameter() will not work. You need to use the API provided by the upload library.
 
Justin Howard
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21149
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic