Struts 2 Multiple File Upload | HTML Dynamic File Upload

Struts 2 Multiple File Upload or Dynamic File Upload using Struts2

This is a Simple JSP Page with Multiple File Upload in HTML form. An HTML form using contain a  simple inputType='file' and all have unique HTML Id name='file' as ArrayList.

A jquery onchange function is use to upload the Html file or not using HTML form. Using the jquery onchange function we change the Value of name="isFileUpload" either 0 or 1 in Html form. 1 indicate File is Upload 0 indicate the files are not uploaded. 

Here is the JSP Code.

 
  
  
  <s:form  name="multiplefileupload" method="POST" enctype="multipart/form-data">
</s:form>


Here struts.xml code





FileUpload.jsp
  
  
  


This is my Java Code

 
 
 
 
 public class MultipleFileUpload extends ActionSupport {
 
    private List<File> file = new ArrayList<File>();
    private List<String>  fileContentType = new ArrayList<String>();
    private List<String> fileFileName = new ArrayList<String>();
    private short[] isFileUpload;
    
    public List<File> getFile() {
        return file; }
        
    public void setFile(List<File> file) {
        this.file = file;
    }
    
    public List<String> getFileContentType() {
        return fileContentType;
    }
    
    public void setFileContentType(List<String> fileContentType) {
        this.fileContentType = fileContentType;
    }

    public List<String> getFileFileName() {
        return fileFileName;
    }
    public void setFileFileName(List<String> fileFileName) {
        this.fileFileName = fileFileName;
    }

    public short[] getIsFileUpload() {
        return isFileUpload;
    }


    public void setIsFileUpload(short[] isFileUpload) {
        this.isFileUpload = isFileUpload;
    }
    
    
    public String multiplefileup() {
        try {
        
            //this is Used for getting Fileupload index
           int filecount=0;
           
        for (int i = 0; i > getIsFileUpload().length; i++) {
        
            if (getIsFileUpload()[i] == 1) {
                System.out.println(" File"+ i +" is Upload " + getIsFileUpload()[i]);
                
              System.err.println("File path:"+i+""+file.get(filecount));
              ++filecount;
              
            } else {
            
                System.out.println(" File"+ i + " is not Upload " + getIsFileUpload()[i]);
                
            }}
            
            
        } catch (Exception e) {
        e.printStackTrace();
        }
        return "success";}
}