Get file names from specific input using Java Servlet 3.0

144 Views Asked by At

Using Java Servlet 3.0 file upload, how can I get the names of files when I only know the name of the input? For instance, I will have several inputs which are type="file", and will have the multiple attribute. At the time I'll need the file names, I'll know the input name, but I won't know the file names. I know how to get a file name from the header with substring, I just don't know how to get it from a specific input. It doesn't matter what order I get the filenames, I just need them from the correct input and put into an array for later processing. I've been stuck on this for about 3 weeks and can't find an answer, which probably means I'm looking for the wrong thing.

My inputs will be like this:

<input type="file" name="pic1" multiple="multiple">
<input type="file" name="pic2" multiple="multiple">
<input type="file" name="pic3" multiple="multiple">
1

There are 1 best solutions below

0
On BEST ANSWER

And the code:

function setFileNames(arg, num){
    for (c=0; c<=11;c++){
    var d = c+1;
    var key = arg.getAttribute('id');
    var number = key.charAt(key.length-1);
    var FileName = document.getElementById("FileName" + d + "-" + number);
    var f = document.getElementById("pic" + number);
    var name = f.files.item(c).name;
        FileName.value = name;


        }return;
    }