• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Servlets, HTML forms, multipart/form-data

 
Ranch Hand
Posts: 427
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When I submit this form, the FooServlet receives an HttpServletRequest with a Content Type value of multipart/form-data
The problem is that the "submitter" attribute and the "serviceClass" attribute are not set. The servlet has no way to read the serviceClass value.

Perhaps the web browser does not send the serviceClass parameter in the HTTP request?
Any advice?
The client web browser is Internet Explorer 6.0 SP1
<FORM ACTION="/servlet/FooServlet"
ENCTYPE="multipart/form-data"
METHOD=POST>
What is your name? <INPUT TYPE=TEXT NAME=submitter><br>
What file are you sending? <INPUT TYPE=FILE NAME=secretDocument><br>
<input type=hidden name="serviceClass" value="FoobarServiceMgr">
<input type="submit" value=Submit><br>
</FORM>
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The problem is that when the browser is sending the data, it is encoding it in a way that the server can't understand.
To decode multipart/form-data encoded data, see the cos package available here
There are other packages available (and no doubt others will come forward and point them out), but the O'Reilly ones seem quite stable and popular
Dave
 
Sean Sullivan
Ranch Hand
Posts: 427
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Situation:
javax.servlet.HttpServletRequest.getParameter(String) returns
null when the ContentType is multipart/form-data
Solutions:
Solution A:
1. download http://www.servlets.com/cos/index.html
2. invoke getParameters() on com.oreilly.servlet.MultipartRequest
Solution B:
1. download http://jakarta.apache.org/commons/sandbox/fileupload/
2. invoke readHeaders() in
org.apache.commons.fileupload.MultipartStream
Solution C:
1. download http://users.boone.net/wbrameld/multipartformdata/
2. invoke getParameter on
com.bigfoot.bugar.servlet.http.MultipartFormData
Solution D:
1. Use Struts. Struts 1.1 handles this automatically
 
reply
    Bookmark Topic Watch Topic
  • New Topic