【发布时间】:2014-12-07 07:29:11
【问题描述】:
我必须一次上传多个文件。我已将这些文件添加到表格中。我想将表中添加的这些文件发送到我的操作类。但我不能这样做??
我的 jquery 是这样的
$(document).ready(function(){
$("#table").hide();
$("#table1").hide();
$('#fileButton').on("click",function(e) {
e.preventDefault();
});
});
通过这个文件被添加到表中
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 的大小为零。
请提供任何有用的解决方案,以便我可以通过表格上传文件
【问题讨论】:
-
那太糟糕了。但如果没有任何实际信息,我不确定您希望任何人能够提供帮助。
-
@xrcwrn 我已通过代码添加。请看一下
-
@DaveNewton 我已经添加了我的代码。请看一下
-
@xrcwrn 但我想知道如何将表中添加的文件的值发送到我的操作类
标签: java jsp file-upload struts2 multiple-file-upload