1

I'm new to Struts2. I have written a JSP page to accept multiple file in single upload option but it doesn't accept multiple file in index page it self.

Please find below the index.jsp file.

<s:form action="upload" method="post" enctype="multipart/form-data">
<label for="myFile">Upload your file</label>
 <s:file name="myFile" multiple="multiple" />
  <s:submit value="Upload files" />
  </s:form>

Please help me out from this problem. it allows single file to select.

Amit Verma
  • 40,709
  • 21
  • 93
  • 115
user3113732
  • 95
  • 1
  • 3
  • 13

1 Answers1

0

From here: Need to upload multiple files at once

JSP

<%@page contentType="text/html; charset=UTF-8" %>
<!DOCTYPE html>
<html>
 <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Multiple File Upload Example</title>
</head>
<body>
    <s:form action="upload" enctype="multipart/form-data" >
        <s:file name="files" multiple="multiple" />
        <s:submit value="Upload files" />
    </s:form>
</body>
</html>

ACTION

public class Upload extends ActionSupport{

private List<File> files;
private List<String> filesContentType;
private List<String> filesFileName;

/* GETTERS AND SETTERS */           

public String execute() throws Exception{
    System.out.print("\n\n---------------------------------------");
    int i=0;
    for (File file : files){
        System.out.print("\nFile ["+i+"] ");
        System.out.print("; name:"         + filesFileName.get(i));
        System.out.print("; contentType: " + filesContentType.get(i));
        System.out.print("; length: "      + file.length());
        i++;
    }
    System.out.println("\n---------------------------------------\n");
    return SUCCESS;
}

}

Struts.xml - Max multipart size:

<constant name="struts.multipart.maxSize" value="20000000" /> 

Interceptor

<interceptor-ref name="fileUpload">
  <param name="maximumSize">10485760</param>
</interceptor-ref>
Community
  • 1
  • 1
Harshit
  • 153
  • 1
  • 11
  • Usually you should [credit the original author](http://stackoverflow.com/a/17212916/1654265) when copying part of the code; not sure what you should do here since you've copied the whole answer. At least go there and upvote the original one. – Andrea Ligios Sep 28 '15 at 08:17