Multipart Forms and File Uploading
Resin 3.0

Features
Installation
Configuration
Web Applications
IOC/AOP
Resources
JSP
Quercus
Servlets and Filters
Databases
Admin (JMX)
CMP
EJB
Amber
EJB 3.0
Security
XML and XSLT
XTP
JMS
Performance
Protocols
Third-party
Troubleshooting/FAQ

Introduction
JSP Compilation
Reference
Tutorials
Articles
FAQ

JSP Page Creation
Request
Topics
Tag Libraries

URL components
JSP environment
Form parameters
Multipart Forms
Headers
Form parameters
Request
Headers

Multipart Forms and File Uploading

Multipart forms let browsers upload files to the website. They also have better handling for internationalization.

Default form handling uses the application/x-www-form-urlencoded content type. Multipart forms use the multipart/form-data encoding.

form.html

<form action="multipart.jsp" method="POST"
      enctype="multipart/form-data">

<input type="file" name="file"><br>

<input type="submit">
</form>

Resin's file uploading stores the uploaded file in a temporary directory. A servlet can get the filename for the temporary file by retrieving the form parameter. In the example, getParameter("file") gets the filename.

Servlets will generally copy the contents of the file to its permanent storage, whether stored on disk or in a database.

multipart.jsp
<%
String fileName = request.getParameter("file");
FileInputStream is = new FileInputStream(fileName);

int ch;
while ((ch = is.read()) >= 0)
  out.print((char) ch);

is.close();
%>


Form parameters
Request
Headers
Copyright © 1998-2006 Caucho Technology, Inc. All rights reserved.
Resin® is a registered trademark, and HardCoretm and Quercustm are trademarks of Caucho Technology, Inc.