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 ...
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
  • 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"
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>
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
Sean Sullivan
Ranch Hand
Posts: 427
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
javax.servlet.HttpServletRequest.getParameter(String) returns
null when the ContentType is multipart/form-data
Solution A:
1. download
2. invoke getParameters() on com.oreilly.servlet.MultipartRequest
Solution B:
1. download
2. invoke readHeaders() in
Solution C:
1. download
2. invoke getParameter on
Solution D:
1. Use Struts. Struts 1.1 handles this automatically
    Bookmark Topic Watch Topic
  • New Topic