Try this link:
Here's some additional information:
Wutka's "Using Java Server Pages and Servlets" - p. 233 has an example.
Also check out the article on Sun's web site:
The code I actually ended up using was much simpler than Sun's example. I reduced the code to only what I needed and hard-coded some values as well. Using the Multipart class in J2EE may have been a better solution, but I wasn't sure how to use the class properly and hard-coding worked fine for my current situation.
Note that the request.getParameter("param") function does not work when using multipart form data. Be aware of this if you have additional parameters that you would like to read on the same page that you are using to upload a file.
// Read the request header line by line until you find the data you're looking for.
// In my case, I'm looking for an XML tree that begins with "<myXML>" and ends with
private String getXMLFromFile(HttpServletRequest request) throws IOException
BufferedReader br = request.getReader();
StringBuffer buffer = new StringBuffer(500000);
// Skip the crap in the header
while ((line = br.readLine()) != null)
if ( line.startsWith("<myXML") )
// Read the XML and skip the crap after XML
while ( line != null )
if ( line.startsWith("</myXML") )
line = br.readLine();