页面显示:a.jsp
 ________
|________|浏览  上传
_________
|________|浏览  上传
 。
 。点上传后,经过处理,将再次回到a.jsp,此时的显示如下:***.doc  x(x为删除图标)
***.jpg  x(x为删除图标)


如果点x后,变成
__________
|_________|浏览 上传
*****.jpg  x(x为删除图标)请问大家有做过类似的上传吗,或者能否告知整个思路呢

解决方案 »

  1.   

    考虑将每一个上传控件做成一个form没?
      

  2.   

    首先上传文件到指定目录(这个不会google一下),然后判断文件目录的文件个数,根据个数显示上传对话框的个数……
      

  3.   

    上传一个文件跟多个文件是一个效果
       如果会上传一个,那么多个对应的就一个数组  【】
    <%@ page language="java" contentType="text/html; charset=gb2312"
        pageEncoding="gb2312"%>
        
    <%@ taglib prefix="s" uri="/struts-tags" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>Insert title here</title><script type="text/javascript">
      
        function addMore()
        {
           var td = document.getElementById("addfile");
           
           var br = document.createElement("br");
           var input = document.createElement("input");
           var button = document.createElement("input");
           
           input.type = "file";
           input.name = "file1";
           
           button.type = "button";
           button.value = "remove";
           
           button.onclick = function()
           {
               td.removeChild(br);
               td.removeChild(input);
               td.removeChild(button);
           }
           
           td.appendChild(br);
           td.appendChild(input);
           td.appendChild(button);
        }
     
    </script>
    </head>
    <body>
       <s:form action="upload" enctype="multipart/form-data" method="post" theme="simple">
       <table border="1px">
           <tr>
              <td>
              userName:
              </td>
              <td>
               <s:textfield label="username" name="username"></s:textfield>
              </td>
           </tr>
           <tr>
              <td>
              password:
              </td>
              <td>
              <s:password label="password" name="password"></s:password>
              </td>
           </tr>
           <tr>
              <td>
              file :
              </td>
              <td id="addfile">
               <s:file name="file1" label="file1"></s:file><input type="button" value="add more" onClick="addMore()">
           
              </td>
           </tr>
             <tr>
              <td>
              <s:submit name="submit" label="提交"></s:submit>
              </td>
              <td>
              
              </td>
           </tr>
       </table>
          
           
          
          
           
       </s:form>
    </body>
    </html>
    这里是动态上传文件 ,可多可少[code=Java]
    public class UploadAction extends ActionSupport {

    private String username;

    private String password;

    private List<File> file1;

    private List<String> file1FileName;

    private List<String> file1ContentType; public String getUsername() {
    return username;
    } public void setUsername(String username) {
    this.username = username;
    } public String getPassword() {
    return password;
    } public void setPassword(String password) {
    this.password = password;
    } public List<File> getFile1() {
    return file1;
    } public void setFile1(List<File> file1) {
    this.file1 = file1;
    } public List<String> getFile1FileName() {
    return file1FileName;
    } public void setFile1FileName(List<String> file1FileName) {
    this.file1FileName = file1FileName;
    } public List<String> getFile1ContentType() {
    return file1ContentType;
    } public void setFile1ContentType(List<String> file1ContentType) {
    this.file1ContentType = file1ContentType;
    } @Override
    public String execute() throws Exception {
    // TODO Auto-generated method stub

    for(int i = 0 ;i < file1.size() ; ++i)
    {
    InputStream is = new FileInputStream(file1.get(i));

    ServletActionContext.getRequest().setCharacterEncoding("gb2312");
    String root = ServletActionContext.getRequest().getRealPath("/upload");
    System.out.println(root);
    File deskfile = new File(root,this.getFile1FileName().get(i));

    OutputStream os = new FileOutputStream(deskfile);

    byte[] buffer = new byte[400];

    int length = 0;

    while((length = is.read(buffer)) > 0)
    {
    os.write(buffer, 0, length);
    }
    os.close();
    is.close();
    }


    return SUCCESS;
    }
    }
    [/code]
      

  4.   

    用ajax实现上传功能;
    用js实现页面效果
      

  5.   

    建议使用ajaxupload.js,支持Jquery,代码量很少且侵入性很小(任意html元素均可作为上传控件)
    代码示例:<script src="<c:url value='/jsp/scripts/ajaxupload.js' />" type="text/javascript"></script><script>
       
       $(document).ready(
        function(){
         $("#assetDt").datepicker({dateFormat: 'yy-mm-dd'});
         $("#assetExpired").datepicker({dateFormat: 'yy-mm-dd'});
         
         new AjaxUpload('#uploadBtn', {
    action: 'assetUsing.action?method=uploadImg', 
    name: 'imgFile',
    onComplete : function(imgName,response){
    $('<li></li>').html(imgName).appendTo($('#uploadInfoDiv .files'));
    //alert("here2=="+response);
    $("#assetOsImgPath").attr("value",response);
    }
    });
    });
    <input name="assetOsImgPath" id="assetOsImgPath" type="hidden" value=''></input>    <div id="uploadBtn" name="uploadBtn" >上传</div>           <p>已上传:
      <ol class="files"></ol>
      

  6.   

    我的是struts2上传。
    FileOutputStream fos = new FileOutputStream(getSavePath()+"\\"+getUploadFileName());
    FileInputStream fis = new FileInputStream(getUpload());
    byte[] buffer = new byte[1024];
    int len = 0 ;
    while((len=fis.read(buffer))>0)
    {
    fos.write(buffer,0,len);
    }