Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Submit multipart and form data

 
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
 
Marshal
Posts: 67451
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • 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
Marshal
Posts: 67451
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • 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
Marshal
Posts: 67451
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • 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



 
Marshal
Posts: 25837
69
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.
 
That is a really big piece of pie for such a tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic