2014-10-12 2 views
3

한 번에 여러 파일을 업로드해야합니다. 이 파일들을 테이블에 추가했습니다. 테이블에 추가 된 파일을 내 액션 클래스에 보내고 싶습니다. 그러나 나는 그렇게 할 수 없다? ?? 이 파일에 의해Struts 2의 테이블을 통해 파일 업로드

$(document).ready(function(){ 
     $("#table").hide(); 
     $("#table1").hide();       
     $('#fileButton').on("click",function(e) { 
      e.preventDefault(); 
     }); 
    }); 

테이블에 추가되고 같은

내 JQuery와는

function addFile() { 
    var fileName = $("#myFile").val(); 

    if(fileName.lastIndexOf('/')!=-1) { 
     fileName = fileName.substring(fileName.lastIndexOf('/')+1); 
    } else if(fileName.lastIndexOf('\\')!=-1){ 
     fileName = fileName.substring(fileName.lastIndexOf('\\')+1); 
    } 

    if(!isFilePresent(fileName)){ 
     $("#table").show(); 
     $("#table1").show(); 
     var row = '<tr><td class="filename">'+fileName+'</td></tr>'; 
     $("#myTable tbody").append(row); 
    } 
    $("#myFile").val(""); 
} 

이 내 양식

<form action="documentUpload" method="POST" enctype="multipart/form-data"> 
    <s:file label="File (1)" id="myFile" name="upload" /> 

    <input type="button" value="ADD" class="Button" 
      id="fileButton" onclick="addFile();"/> 

    <table id="myTable"> 
     <thead> 
      <tr> 
      <div>File Type</div> 
      </tr> 
     </thead> 
     <tbody> 
     </tbody> 
    </table> 

    <s:submit value="Upload" id="table1"/> 
</form> 

이 내 struts.xml 항목

입니다
<action name="documentUpload" class="objDocumentUpload" method="upload"> 
    <result name="success">/jsp/documentUpload2.jsp</result> 
    <result name="input">/jsp/dashboard.jsp</result> 
</action> 

이것은 내 액션 클래스입니다.

public class FileUploadAction { 
    private List<File> uploads = new ArrayList<File>(); 

    public String upload() throws Exception {  
     int upload12=uploads.size(); 
     System.out.println(upload12); 
     return SUCCESS; 
    } 

테이블에 파일을 성공적으로 추가 할 수 있습니다. 업로드 버튼을 클릭하면 컨트롤이 내 액션 클래스로 전송됩니다. 그러나 업로드 방법에서 나는 upload12의 크기를 0으로 얻고 있습니다. 나는 테이블을 통해 파일을 업로드 할 수 있도록

나에게 어떤 도움이되는 솔루션을 제공하십시오

+0

너무 나쁩니다. 그러나 실제 정보가 없으면 어떻게하면 누구를 도울 수 있을지 잘 모르겠습니다. –

+0

코드를 여기에 게시하십시오. – xrcwrn

+0

@xrcwrn 코드별로 추가했습니다. 제발 봐 – suraj

답변

0

테이블 그냥 클라이언트 표시하고 POST 동안 사용되지 않습니다. 테이블 행 대신 양식에 "파일"필드를 만들어야합니다.

+0

이 제안을 코멘트로 남겨주는 것이 좋습니다. – sasi