1

I have a simple form that uploads a selected file using Apache Commons Upload 1.2.2. The form has only one field to specify one file name, and 2 buttons, Browse and Submit, like so:

<form action="upload" enctype="multipart/form-data" method="POST">
    <input type="file" name="filename">
    <input type="submit"/>
</form>

I'd like to be able to make this a one click operation (as soon as the file is selected, it is submitted), rather than 2 button clicks (file select then submit). Any suggestions would be appreciated, TIA.

MuffinMan
  • 889
  • 1
  • 8
  • 28

2 Answers2

2

Let JavaScript submit the parent form on change of the input field.

<form action="upload" method="post" enctype="multipart/form-data" >
    <input type="file" name="filename" onchange="submit()" />
</form>  

Unrelated to the concrete question, based on your question history you seem to be already using Servlet 3.0. I'd suggest to just use the new API provided request.getPart() method instead of Apache Commons FileUpload. See also How to upload files to server using JSP/Servlet?

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
0

You probably need some Javascript or Flash component to achieve this.

E.g. http://blueimp.github.com/jQuery-File-Upload/

Udo Held
  • 12,314
  • 11
  • 67
  • 93