解决方案 »

  1.   

    首先要确定,页面的值能不能自动赋值给 Action的属性 List可以debug一下,看下list中有多少元素文件上传毕竟和页面值传递不一样
      

  2.   

    String savePath = ServletActionContext.getServletContext().getRealPath("/upload/"+uploadFileName.get(i));//+uploadFileName.get(i)这个有问题吧?刚开始文件肯定是不存在的吧?
     FileInputStream fis = new FileInputStream(upload.get(i));
     FileOutputStream fos = new FileOutputStream(savePath);//保存的时候加上uploadFileName.get(i)才对。
      

  3.   

    可以把控制台输出结果发上来: System.out.println(uploadFileName.get(i));,这样也可以缩小范围
      

  4.   

    执行了你的程序,报错:FIleNotFoundException不知道哪里设置,不同于楼主指定位置没有任何文件因此不使用 IO 流,改用如下代码,成功执行:public class UploadAction extends ActionSupport {
    /**
     * 
     */
    private static final long serialVersionUID = 3258740595336733237L;
    private File[] upload;
    private String[] uploadFileName; public String execute() throws IOException {
    for (int i = 0; i < upload.length; i++) {
    System.out.println(uploadFileName[i]);
    String savePath = new String("D:/upload/" + uploadFileName[i]);
    System.out.println(savePath);
    FileUtils.copyFile(upload[i], new File(savePath));
    }
    return SUCCESS;
    } /**
     * @return the upload
     */
    public File[] getUpload() {
    return upload;
    } /**
     * @param upload the upload to set
     */
    public void setUpload(File[] upload) {
    this.upload = upload;
    } /**
     * @return the uploadFileName
     */
    public String[] getUploadFileName() {
    return uploadFileName;
    } /**
     * @param uploadFileName the uploadFileName to set
     */
    public void setUploadFileName(String[] uploadFileName) {
    this.uploadFileName = uploadFileName;
    }
    }
      

  5.   

    多文件上传和单文件上传是不一样的,你应该去看看struts的多文件上传,肯定是后面上传的文件把你前面上传的覆盖了,如果是多文件上传的话,那么前台应该是一个数组形式,后台也有相应的改变的。
    http://www.cnblogs.com/linjiqin/archive/2011/03/21/1990688.html
      

  6.   

    doUpload方法改下,万一项目下没有upload目录是需要创建的
        public String doUpload() throws IOException {
            for (int i = 0; i < upload.size(); i++) {
                System.out.println(uploadFileName.get(i));
                String uploadPath= ServletActionContext.getServletContext().getRealPath("/upload/");
                File file = new File( uploadPath);
                if(!file.exists()){
                    file.mkdir();
                }
                String savePath =uploadPath +File.separator+ uploadFileName.get(i);
                FileInputStream fis = new FileInputStream(upload.get(i));
                FileOutputStream fos = new FileOutputStream(savePath);
                IOUtils.copy(fis, fos);
                fos.flush();
                fis.close();
                fos.close();
            }
            return SUCCESS;
        }