caucho
Resin
FAQ
Reference Guide
Demo
Tutorial

JSP page
Config
URLs
Database Forms
XTP Copy
Hello Tag
Vary Filter
HardCore
Mailing Forms
Beans
Cache
XSL Filter
run-at

Forms
File Upload
Headers
 Multipart Forms and File Uploading

Forms
URLs
Headers

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();
%>

Forms
URLs
Headers
Copyright © 1998-2002 Caucho Technology, Inc. All rights reserved.
Resin® is a registered trademark, and HardCoretm and Quercustm are trademarks of Caucho Technology, Inc.