• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

How to get the request parameters while the enctype is multipart/form-data

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I have the requirement that the user can upload an image along with his other details. So, I created simple html form with enctype of multipart/form-data. I am done with my file upload part. But, when i am trying to get the other values using request.getParameter(fieldName), it is returning null. I have found another way to get the values. And i am able to retrive those values when the enctype is normal one.

I just wanted to know the reason for that. Why request.getParameter is always returning null when the enctype is multipart/form-data is null.

Thanks
Suresh
 
Sheriff
Posts: 67753
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
getParameter() and its related methods will not work for a multi-part request.

Whatever upload library you are using will have mechanisms available to get the submitted data. If you are parsing the multi-part request yourself (not recommended) then you aren't doing it right if you haven't located the submitted data.
 
Suresh Chandra sekaran
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks bibeault. Actually, I am using the parse method available in upload library only. I would like to know, why getParameter() and its related methods are not getting the values from request. Can anyone explain it?
 
Bear Bibeault
Sheriff
Posts: 67753
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The HttpServletRequest instance will only parse the body of the request if the enctype is "application/x-www-form-urlencoded", which is the default for the <form> tag.

If it went ahead and read the request body, it would no longer be available for your upload library to fetch and parse.

If you let us know which upload library you are using, perhaps someone can suggest how to use it to obtain the extra parameters.
 
Suresh Chandra sekaran
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you. I am using apache fileupload package. I could retrieve the extra parameters also using the parse method.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, "you say you have found another way to get the values." Nowdays I met the same problem ==========Why request.getParameter is always returning null when the enctype is multipart/form-data is null. I wonder how to get the parameters , thank you!!

Thanks
 
Bear Bibeault
Sheriff
Posts: 67753
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It has already been explained. When the enctype is multipart, the servlet container will not parse it (at least not prior to Servlets 3.0).

That's why the 3rd party libraries are popular. Parsing a multipart request is complicated. See the JspFaq for more info.
 
yang erwei
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually ,my main attention is your another way .....You know ..........

Thanks !!!
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use Apache Common 's File Upload
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic