private List uploadFile(WebKnowledgeForm weKnowledgeForm)//我的form继承过actionform里头除了new了对应实体对象 //外,还有个集合 List<FormFile> myFiles=new ArrayList<FormFile>();
throws IOException {
List list = new ArrayList();
String filenames = "";
Hashtable<String,FormFile> files = 
weKnowledgeForm.getMultipartRequestHandler().getFileElements();
              System.out.println(files.size()+"元素的长度");//输出 是 1,无论我有十个八个附件都是JSP页面上的的提交是这样的<form action="${ctx}/knowledge.do?param=doSave" method="post"
encType="multipart/form-data">
<TABLE>
<tr>
.......
<tr>
<tr>
<table id="tablefiles" border="0" cellSpacing=0 cellPadding=0>
<tr style="border: 0px">
<td>
<input type="file" name="myfile" style="width: 300px;" />
</td>
<td bordercolor="#FFFFFF">
<input type="button" value="增加一个上传" onclick="addFile()" />
</td>
</tr>
</table></tr></TABLE>

解决方案 »

  1.   

     <input type="file" name="myfile" style="width: 300px;" />   你上传18个附件就需要18个name ,你把name改成不一样的。
      

  2.   

    这里的name最好写成随机生成的动态的
      

  3.   

    一般用common-fileupload.jar  我们公司包装过的..所以发给你代码,你也看不懂.
      

  4.   

    补充:
    var i=0; 
    function addFile(){ 
    i++; 
    var tableFiles = document.getElementById("tablefiles"); 
    var Row  =tableFiles.rows; 
    if(parseInt(Row.length)>9){ 
    alert("一次最多只能上传10个附件文件") 
        return false; 

    var newRow=tableFiles.insertRow(tableFiles.rows.length); 
    var Cells=newRow.cells; 
    var newCell=Row(newRow.rowIndex).insertCell(Cells.length); 
    newCell.innerHTML= "<input type=file Contenteditable='false' style='width:300px;' name='myfile' />" ;
    var newCell2=Row(newRow.rowIndex).insertCell(Cells.length); 
    newCell2.innerHTML="<input type=button value=删除 onclick='delFile()'/>"; 
    } function findTD(o){ 
    if (o.nodeName=="TR"||o.nodeName=="TABLE") return; 
    if(o.nodeName=="TD") 
    return (o); 
    else 
    return (o.parentElement); 
    } function delFile(){ 
         var tableFiles = document.getElementById("tablefiles"); 
         o = findTD(event.srcElement); 
        tableFiles.deleteRow(o.parentElement.rowIndex*1); 


      

  5.   


    //在name后面加i,需要不同的name
    newCell.innerHTML= "<input type=file Contenteditable='false' style='width:300px;' name='myfile'+i />" ;
      

  6.   

    myfile 名字换了 就爆错了
    java.lang.NullPointerException
    at java.lang.Class.isAssignableFrom(Native Method)
    at org.apache.struts.util.RequestUtils.rationalizeMultipleFileProperty(RequestUtils.java:506)
    at org.apache.struts.util.RequestUtils.populate(RequestUtils.java:459)
    at org.apache.struts.action.RequestProcessor.processPopulate(RequestProcessor.java:823)
    at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:194)
    而且未进action,不改名字是会走的action的