Load file via table in Struts 2
I need to upload multiple files at once. I added these files to the table. I want to send these files added to the table to my action class. but i can't do it ??
my jquery is like
$(document).ready(function(){
$("#table").hide();
$("#table1").hide();
$('#fileButton').on("click",function(e) {
e.preventDefault();
});
});
these files are added to the table
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("");
}
This is my form
<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>
This is my struts.xml entry
<action name="documentUpload" class="objDocumentUpload" method="upload">
<result name="success">/jsp/documentUpload2.jsp</result>
<result name="input">/jsp/dashboard.jsp</result>
</action>
This is my action class.
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;
}
I can successfully add files to the table. when I click the Load button, the control is passed to my action class. But in the upload method I get the size upload12
as zero.
Please provide me with some useful solution so that I can upload the file via a table
+3
source to share