2013-06-26 1 views
1

여러 파일을 서버에 업로드해야합니다. 내가 다음 코드 JSP를 썼다 :스트럿츠로 여러 파일 업로드 1

<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 
+0

하지가 필요하십니까? –

+0

무슨 뜻인지 몰랐습니까? – fatiDev

+1

특별한 파일 배열을 소개합니다. FormFile image0 및 image1을 개선하십시오. (Struts는 오랫동안 잊혀진 것입니다.) 하나의 FormFile로 만들 수 있다면 두 번째는 간단해야합니다. –

답변

1

당신은 사용 = "업로드"입력 이름으로 유사한 양식을 사용 필요를 제공합니다

<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> 

및 콩에 당신은 '이름 = image0`와'이름 = image1`을 가지고, 프로그램 안전

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; } 
}