File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Processing multipart/form-data Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Processing multipart/form-data" Watch "Processing multipart/form-data" New topic

Processing multipart/form-data

Christopher Elkins
Ranch Hand

Joined: Oct 26, 2004
Posts: 45
One of my jsp pages allows a user to upload a file from their computer to the server. The page contents are submitted via HTML Form using the POST method and an enctype equal to "multipart/form-data". I need to write a class that will properly handle this type of request. I have looked through the forum and found several threads refering to this issue. They all state the same thing; use some third-party software. This is not an option for me since all of the code that we use must be developed internally. My question is this, is there any information out there on how to write this code? If so, where? Thanks for any help that you can provide.
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63540

If you must write all the code that you use (do they expect you to write your own servlet container as well?), you'll need to parse the multi-part request yourself.

I'd grab one of the 3rd party tools that you found mentioned and look at the multi-part parsing code to learn what it entails. In particular, I remeber that looking at the O'Reilly MultipartParser class was very instructive.

[Asking smart questions] [About Bear] [Books by Bear]
Christopher Elkins
Ranch Hand

Joined: Oct 26, 2004
Posts: 45
Thanks Bear. I'll take a look. Yeah, if it's not part of the java, javax or oracle packages we pretty much have to reinvent the wheel. It's a shame that it usually turns out square.
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: Processing multipart/form-data
It's not a secret anymore!