Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring 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
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Servlets, HTML forms, multipart/form-data

 
Ranch Hand
Posts: 427
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
 
    Bookmark Topic Watch Topic
  • New Topic