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

I am using Struts2 to upload multiple files:

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

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

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

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

You can use the HTML5 files property of the <input type="file" /> element like follows:

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

<p>Selected files:</p>

<div id="fileList"></div>

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .
Read More:   How to reduce stack trace when throwing error (point to call site)

Similar Posts