You want to use the com.oreilly.servlet classes that O'Reilly author Jason Hunter has developed to handle file uploads.
Download the distribution ZIP file from http://www.servlets.com/cos/index.html. Add the cos.jar file, which is part of the distribution to the WEB-INF/lib directory of your web application. Make sure that you adhere to the software license when using the library.
A JAR file named cos.jar includes the com.oreilly.servlet and com.oreilly.servlet.multipart packages. These packages include several classes, such as all of the Java classes that begin with "Multipart," which can be used to handle file uploading in a servlet.
Download the latest ZIP file containing the distribution from http://www.servlets.com/cos/index.html. The contents of the ZIP file include cos.jar , which you need to add to the WEB-INF/lib directory of your web application. In your servlet, you then import the classes that you want to use:
import com.oreilly.servlet.MultipartRequest; import com.oreilly.servlet.multipart.FileRenamePolicy;
Before you have integrated these classes into your code, make sure that you have read the accompanying software license for this code: http://www.servlets.com/cos/license.html.
Recipe 8.1 on preparing the HTML for a file upload; Recipe 8.5 on handling a single file upload; Recipe 8.6 on handling multiple file uploads in a servlet; Recipe 8.5 on controlling file naming; Recipe 8.6 on using a JSP to handle file uploads; the homepage for com.oreilly.servlet : http://www.servlets.com/cos/index.html; the RFC 1867 document on form-based file uploads: http://www.ietf.org/rfc/rfc1867.txt.