2012-08-24 2 views
3

내가 가진 JSP 코드jsp를 사용하여 자바 (스트럿츠)에서 여러 이미지를 업로드하는 방법은 무엇입니까?

college.jsp 페이지이 JSP를 사용하여 프로젝트

폴더에 저장 스트럿

총 이미지에서 여러 이미지를 업로드하지만, 내가 원하는 방법

<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %> 

<html> 
<head> 
</head> 
<body> 
<html:form action ="/college.do"> 
<fieldset> 
<legend>COLLEGE INFORMATION :</legend> 
<pre> 
Gallery Images: <input type="file" name="file[]" multiple/> 
<html:submit value = "S U B M I T"/> 
</fieldset> 
</html:form> 
</body> 
</html> 
CollegeAction 클래스와 CollegeForm 클래스로하는 방법 코드 도와주세요

+0

@The 엘리트 신사는이 괜찮 나에게 – Kumar

답변

0

이런 일을하고 싶을 수도 있습니다.

private FormFile image1; 
private FormFile image2; 
private FormFile image3; 

을 자신의 getter 및 setter와 ..along : 당신의 JSP 파일에서

<html:file property="image1"/> 
<html:file property="image2"/> 
<html:file property="image3"/> 

망가 이미지 변수를 만들, 당신의 Form 파일에 HTML 폼의 속성을 다음 enctype="multipart/form-data"

을 설정하는 것을 잊지 .

OutputStream bos = null; 
InputStream stream = null; 
try { 
    String fileName = form.getImage().getFileName(); 
    String directory = "C:/your_folder"; 
    File f = new File(directory); 
    if (!f.exists()) { 
    f.mkdir(); 

    if (!"".equals(fileName)) { 
    stream = form.getImage1().getInputStream(); 
    bos = new FileOutputStream(directory + fileName); 
    int bytesRead = 0; 
    byte[] buffer = new byte[8192]; 

    while ((bytesRead = stream.read(buffer, 0, 8192)) != -1) { 
     bos.write(buffer, 0, bytesRead); 
    } 
    } 
    } 
} catch (Exception e) { 
e.printStackTrace(); 
} 
+0

도와주세요하지만 난 하나 (

그런 다음 서버 측에서 이미지 생성에 대한 변수를 사용할 수있는 파일 속성 = "image1에 "/>) 여러 이미지를 찍는 줄 – Kumar

관련 문제