使用struts 1上传多个文件

时间:2013-06-26 16:33:13

标签: file-upload struts-1

我需要将多个文件上传到服务器。 我写了下面的代码 jsp:

<form action="fileUpload.do" method="post" enctype="multipart/form-data">

   <input type="file" name="image" />
  <input type="file" name="image" />
    </div>
    </div>
    <input type="submit" value="submit">  
    </form>

ActionForm:

public class UploadForm extends ActionForm {

private FormFile[] image = new FormFile[2] ;


public FormFile[] getImage() {
    return image;
}

public void setImage(FormFile[] image) {
    this.image = image;
}

public ActionErrors validate(ActionMapping mapping,
        HttpServletRequest request) {
    // TODO Auto-generated method stub
    return null;
}


public void reset(ActionMapping mapping, HttpServletRequest request) {
    // TODO Auto-generated method stub
}

它给了我这个错误

java.lang.IllegalArgumentException: argument type mismatch

1 个答案:

答案 0 :(得分:1)

您需要使用输入名称=“upload”的类似表单

<form action="fileUpload.do" method="post" enctype="multipart/form-data">
   <input type="file" name="upload" />
   <input type="file" name="upload" />
   <input type="submit" value="submit">  
</form>

在bean方面你需要

public class UploadBean extends BaseBean implements HttpSessionBindingListener {

    protected ArrayList<FormFile> uploaded = new ArrayList<>(); 


    public void setUpload(List<FormFile> file) { uploaded.addAll(file); }

    public List<FormFile> getUpload() { return uploaded; }
}