• Post Reply Bookmark Topic Watch Topic
  • New Topic

Servlets, HTML forms, multipart/form-data

 
Sean Sullivan
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>
 
David O'Meara
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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!