한 번에 여러 파일을 업로드해야합니다. 이 파일들을 테이블에 추가했습니다. 테이블에 추가 된 파일을 내 액션 클래스에 보내고 싶습니다. 그러나 나는 그렇게 할 수 없다? ?? 이 파일에 의해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으로 얻고 있습니다. 나는 테이블을 통해 파일을 업로드 할 수 있도록
너무 나쁩니다. 그러나 실제 정보가 없으면 어떻게하면 누구를 도울 수 있을지 잘 모르겠습니다. –
코드를 여기에 게시하십시오. – xrcwrn
@xrcwrn 코드별로 추가했습니다. 제발 봐 – suraj