3

我必须一次上传多个文件。我已将这些文件添加到表格中。我想将表中添加的这些文件发送到我的操作类。但我不能这样做??

我的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设为零。

请为我提供任何有用的解决方案,以便我可以通过表格上传文件

4

1 回答 1

0

您的表格只是一个客户端显示,不会在 POST 期间使用。您需要在表单中创建“文件”字段,而不是表格行。

于 2014-10-29T11:32:06.043 回答