O'Reilly logo

Struts 2 Design and Programming: A Tutorial by Budi Kurniawan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 12. File Upload

HTTP file upload is specified in Request For Comments (RFC) 1867. Struts’ File Upload interceptor supports HTTP file upload by seamlessly incorporating the Jakarta Commons FileUpload library that contains a multipart parser. This chapter discusses file upload in general and how you can do single and multiple file uploads in Struts.

File Upload Overview

When using an HTML form to upload a file or multiple files, the enctype attribute of the form must be assigned multipart/form-data and the form method must be post. The form should look like this.

<LINELENGTH>90</LINELENGTH>
<form action="anAction" enctype="multipart/form-data" method="post">
...
</form>

To enable the user to select a file you must have an <input type=“file”> ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required