How to display selected file names before loading multiple files in Struts2?

I use Struts2 to upload multiple files:

<s:file name="files" multiple="multiple" /> 

When I select multiple files, it displays the number of files, for example. 3 files.

The project requirements are that the user should be able to see which files he selected before downloading .

Is it possible to display the names of the selected files in a list, or perhaps in the control itself?

+13
javascript html5 jsp file-upload struts2
source share
2 answers

You can use the HTML5 files property of the <input type="file" /> element, for example, the following:

 updateList = function() { var input = document.getElementById('file'); var output = document.getElementById('fileList'); output.innerHTML = '<ul>'; for (var i = 0; i < input.files.length; ++i) { output.innerHTML += '<li>' + input.files.item(i).name + '</li>'; } output.innerHTML += '</ul>'; } 
 <input type="file" name="file" id="file" multiple onchange="javascript:updateList()" /> <br/>Selected files: <div id="fileList"></div> 
+27
source share

I GET THIS ERROR ::

Uncaught ReferenceError: updateList is not defined in HTMLInputElement.onchange ((index): 28) onchange @ (index): 28

What am I doing???

0
source share

All Articles