本人想实现一个功能 使用struts的bs结构
在客户端同时上传多个 文件 
可我不想用多个<input file哪位有好办法或者例子 
可以用js 或者各种办法 大家帮忙
最好是能够制定一个文件之后 该文件夹所有文件都能上传的

解决方案 »

  1.   

    我看你还是用多个 <input file 吧
      

  2.   

    选择文件夹上传的功能需要插件,或都flash(这个没有试过.)
    如果只是页面传文件的话,要中能还是要借助<input file>
      

  3.   

    在选择的时候可以使用一个input,但是真正上传的时候可以隐式的转换为多个input,再上传
      

  4.   

    这个问题正好我刚弄完。
    jsp页面部分可以用js来实现 建立名字不相同的file代码如下<table width="95%" border="0" cellpadding="0" cellspacing="1" class="biaogeys4_1">
     <tr>
        <td align="right" class="biaogeys4" width="10%">公文附件:</td>
        <td align="left" valign="middle" class="biaogeys4" colspan="3" id="file">
          <font color="red">上传附件不能为exe格式,单个附件不能超过5MB,最多只能上传10个附件</font><br> 
          <input type="file" name="uploadFile" id="uploadFile" size="30">
                    <input name="继续添加附件" type="button" value="继续添加附件" onclick="AddMore()">   
                   
        </td>
        </tr>
    </table>js部分如下:function AddMore(){
       // 验证上传附件不能超过10个
      if(num>8){
       alert("上传附件不能超过10个");
       return false;
      }
           var more = document.getElementById("file");
           var br = document.createElement("br");
           var input = document.createElement("input");
           var button = document.createElement("input");
           num++;
           input.type = "file";
           input.name = fileName+num;
           input.size = "30";
           button.type = "button";
           button.value = "取消";
           
           more.appendChild(br);
           more.appendChild(input);
           more.appendChild(button);
           
           button.onclick = function(){
               more.removeChild(br);
               more.removeChild(input);
               more.removeChild(button);
           }; 
      }
    在使用struts单个文件上传时我们在ActionForm 中定义FormFile ,但此时我们的上传有n个,不能在ActionForm 定义n个FormFile,解决办法如下:在ActionForm 中不定义FormFile ,在 Action中直接获取
    代码如下://获得form
    MessageForm messageform = (MessageForm) form;
    Hashtable fileh = messageform.getMultipartRequestHandler()
    .getFileElements();
    for (Iterator it = fileh.keySet().iterator(); it.hasNext();) {
    String key = (String) it.next();
    // 得到附件,jsp页面中表单域的名称不能相同,否则只能得到最后一个附件
    FormFile formfile = (FormFile) fileh.get(key);
    }
    在jsp页面中必须每一个file的name是不同的,否则得不到所有的file
      

  5.   

    <div id="divComposeFileUploader" title="按住Ctrl键可选择多个附件" style="position: absolute; width: 48px; height: 22px; top: 0px; left: 0px;">
    <embed id="divComposeFileUploader_Object" name="divComposeFileUploader_Object" 
    src="/a/h/FileUploader_v1.swf" 
    flashvars="apiMulti=1&amp;
    apiListener=MM.compose.fileUploader.dispatch" 
    quality="high" 
    wmode="transparent" 
    allowscriptaccess="always" 
    type="application/x-shockwave-flash"
    height="100%" 
    width="100%">
    </div>
      

  6.   

    struts可以同时上传多个文件,首先在你的ActionForm中定义n个FormFile属性,如:import org.apache.struts.upload.FormFile;
    public class UpForm extends ActionForm { private FormFile formFile1;
    private FormFile formFile2; public FormFile getFormFile1() {
    return formFile1;
    } public void setFormFile1(FormFile formFile1) {
    this.formFile1 = formFile1;
    } public FormFile getFormFile2() {
    return formFile2;
    } public void setFormFile2(FormFile formFile2) {
    this.formFile2 = formFile2;
    }
    }然后在struts-config中定义form-beans:<form-bean name="upForm" type="UpForm"></form-bean>
    action中定义<action path="/upload" name="upForm" scope="request" type="Updeal"></action>
    在上传页面定义两个<html:file size="50" property="formFile1"/>
    <html:file size="50" property="formFile2"/>
    在上传处理action中:UpForm form = (UpForm) form;
    FormFile formFile1 = form.getFormFile1();//第一个附件
    FormFile formFile2 = form.getFormFile2();//第二个附件
    //......FormFile有个getFileData()方法可以获得上传文件的字节流,你把它保存到文件中上传就ok了
      

  7.   

    感谢楼上几位 但是 如果用多个input的话 那么不是要客户选择多个文件么  现在想要的是 只选择一个文件 然后其他文件自动上传  现在是想让用户只选择一个 其他跟着上传 或者直接让客户选择多个
      

  8.   

    这个我才做没多久~~用的是swfupload+struts~~很好用~~