Multipart Forms and File Uploading
Resin 3.0

Orientation
Features
Installation
Configuration
Web Applications
JSP
Servlets and Filters
Portlets
Databases
Admin (JMX)
Amber
Security
XML and XSLT
XTP
Resources
Performance
Protocols
Third-party
Troubleshooting/FAQ

Introduction
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-2003 Caucho Technology, Inc. All rights reserved.
Resin® is a registered trademark, and HardCoretm and Quercustm are trademarks of Caucho Technology, Inc.