1、jspsmart
需要修改:用 JS 写一个新增 <input type="file"> 的方法,就可以支持多个文件上传了
2、用 struts 自带的 formfile 上传,同样需要写一个新增 file 的方法

解决方案 »

  1.   

    有很多控件都可以支持多文件上传
    如:jspsmartupload,fckeditor,Ajax UpLoadFile ,SWFupload等
      

  2.   


    这个东东不错:jspsmartupload.jar网上可以抄代码。
      

  3.   


    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
    <%@ taglib prefix="s" uri="/struts-tags"%><%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
        <base href="<%=basePath%>">
        
        <title>My JSP 'upload.jsp' starting page</title>
        
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">    
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->

      <script type="text/javascript">
      <!--
        function addMore()
        {
         var td = document.getElementById("more");
         var br = document.createElement("br");
         var input = document.createElement("input");    
         var button = document.createElement("input");
        
         input.type = "file";
         input.name = "file";
        
         button.type = "button";
         button.value = "Remove";
        
         td.appendChild(br);
         td.appendChild(input);
         td.appendChild(button);       
        
         button.onclick = function()
         {
         td.removeChild(br);
         td.removeChild(input);
         td.removeChild(button);
         }
              
        }
      //-->
      </script>  </head>
      
      <body>  
      
        <s:fielderror cssStyle="color: red;"></s:fielderror>
       
      <s:form action="upload" theme="simple" method="post" enctype="multipart/form-data">
        <table width="50%" align="center" border="1">
          <tbody>
            <tr>
              <td>userName</td>
              <td><s:textfield name="userName"></s:textfield></td>
            </tr>
            
            <tr>
              <td>password</td>
              <td><s:password name="password"></s:password></td>
            </tr>
            
            <tr>
              <td>file</td>
              <td id="more">
                <s:file name="file"></s:file>
                <input type="button" value="add more..." onclick="addMore();"/>
              </td>
            </tr>
            
            <tr>
              <td>submit</td>
              <td><s:submit value="submit"></s:submit></td>
            </tr>        
          </tbody>    
        </table>
      </s:form>  
      
      
      </body>
    </html>这个应该符合你的需求,用struts2实现,其它的类似,稍改下即可.
      

  4.   

    参考下吧。。
    <body>
        <%
    SmartUpload su = new SmartUpload();
    //初始化
    su.initialize(pageContext);
    //pageContext.setAttribute("uname","zhangsan",PageContext.APPLICATION_SCOPE);
    //设置文件大小
    su.setMaxFileSize(10 * 1024 * 1024);
    //上传

    su.upload();
    String musicname = su.getRequest().getParameter("type11");
    String musicid=su.getRequest().getParameter("type22");

    MemberPO memberPO = (MemberPO) session.getAttribute("memberPO");
    MusicBO musicBO=new MusicBO();
    int count = su.save("F:\\wuyao\\user\\" + memberPO.getMname()+ "\\musictype\\"+musicname+"\\" );
    Files f = su.getFiles();

    if(count>0)
    {
    for(int i=0;i<6;i++)
    {
    MusicPO musicPO=new MusicPO();
    musicPO.setMcontent("");
    musicPO.setMmusictypeid(Integer.parseInt(musicid));
    musicPO.setMname(su.getRequest().getParameter("music"+(i+1)));
    musicPO.setMpath("F:\\wuyao\\user\\" + memberPO.getMname()+ "\\musictype\\"+musicname+"\\"+su.getRequest().getParameter("music"+(i+1)));
    musicPO.setMsininger("");
    if(su.getRequest().getParameter("music"+(i+1)).length()!=0&&f.getFile(i).getFilePathName().length()!=0&&musicBO.AddMusic(musicPO)>0)
    {
    out.print(su.getRequest().getParameter("music"+(i+1))+"音乐上传成功<br>");
    }
    }
    out.print("总计上传成功"+count+"个文件<a href='view/uploadmusic.jsp'><p>返回</a>");
    }else
    {
    out.print("上传失败<br><a href='view/uploadmusic.jsp'>返回</a>");
    }
    %>
      </body>
      

  5.   

    这个相当于提交文件数组到action去的,你一个文件可以取了,那多个用循环应该也可以取吧.但struts2相对好取点,1.2的麻烦些吧.
      

  6.   

    附件,就用<input type="file">就可以实现啊
      

  7.   


    // 新建一个SmartUpload对象
    SmartUpload su = new SmartUpload();
    // 上传初始化
    su.initialize(pageContext);
    在Action 中怎样上传初始化 su.initialize(pageContext);我试了pageContext的对象得到的是NULL
    JspFactory _jspxFactory = JspFactory.getDefaultFactory();
                javax.servlet.jsp.PageContext pageContext =_jspxFactory.getPageContext(this.getServlet(),request,response,null,true,8192,true);
    这样pageContext对像还是NULL资料引用:http://www.knowsky.com/3136.html
      

  8.   

    做了一个例子:
    http://download.csdn.net/source/1396092myeclipse 工程
    上传页:index.html
    文件都保存在 C 盘根目录下有两个例子:
    一个是 jspsmart + strust 1.2 
    另一个用的 struts 自带的 formfile环境:winxp jdk1.4.2 tomcat5.0或weblogic8.1发布前,最好先编译一下,毕竟JDK版本太老了
    下载居然要1分资源分,我太邪恶了,哇哈哈哈~~~
    (发表评论时,点发表评论输入框上面的星星评分,消耗资源分可以还回来)
      

  9.   


    我想问一下,我的程序是用SSH框架,在Action中是不是不能呢???
      

  10.   

    例子: 
    http://download.csdn.net/source/1396092 
      

  11.   

    15楼的例子就是 struts 的
    和 hibernate 、spring 不冲突
      

  12.   


    用的 struts 自带的 formfile 吗?
    可是我是多附件上传呀
      

  13.   

    struts2就有file标签的,可以实现多附件
      

  14.   


    <%@ page language="java" pageEncoding="GB2312"%>
    <style>
    *{ font-size:12px;}
    </style>
    <div id="file" >
                    <input type="file" name="file1">
                    <input name="提交" type="submit" value="上传头像">      
                    <input name="继续添加附件" type="button" value="继续添加附件" onclick="AddMore()">    
    </div>
    <script type="text/javascript">
            function AddMore(){
                var more = document.getElementById("file");
                var br = document.createElement("br");
                var input = document.createElement("input");
                var button = document.createElement("input");
                
                input.type = "file";
                input.name = "file";
                
                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);
                }; 
            }
        </script>