数组能解决这个问题的吧.
在action中用这个同名的数组接受.

解决方案 »

  1.   

    晕,我的代码还是在网上找的呢,外泄什么啊,呵呵下面是Action层代码,没有logic层,注释也不是我写的这样能实现文件上传,但如果上传同名的文件,就会在服务器端把原来的文件覆盖掉,
    不知道这个问题如何解决,是改文件名吗?还是用文件夹分类?package actions;import java.io.*;
    import javax.servlet.http.*;
    import org.apache.struts.action.*;
    import org.apache.struts.upload.FormFile; import forms.UpLoadForm;/**
    * <p>Title:UpLoadAction</p>
    * <p>Description: QRRSMMS </p>
    * <p>Copyright: Copyright (c) 2004 jiahansoft</p>
    * <p>Company: jiahansoft</p>
    * @author wanghw
    * @version 1.0
    */public class UpLoadAction extends Action {
      public ActionForward execute(ActionMapping mapping,
                                   ActionForm form,
                                   HttpServletRequest request,
                                   HttpServletResponse response)
          throws Exception {
        if (form instanceof UpLoadForm) {//如果form是uploadsForm
            String encoding = request.getCharacterEncoding();
            if ((encoding != null) && (encoding.equalsIgnoreCase("utf-8")))
            {
                response.setContentType("text/html; charset=gb2312");//如果没有指定编码,编码格式为gb2312
            }
            UpLoadForm theForm = (UpLoadForm ) form;
            FormFile file = theForm.getTheFile();//取得上传的文件
            try {
              InputStream stream = file.getInputStream();//把文件读入
              String filePath = request.getRealPath("/");//取当前系统路径
              System.out.println(filePath);
              ByteArrayOutputStream baos = new ByteArrayOutputStream();
              OutputStream bos = new FileOutputStream(filePath + "/" +
                                                      file.getFileName());//建立一个上传文件的输出流
              //System.out.println(filePath+"/"+file.getFileName());
              int bytesRead = 0;
              byte[] buffer = new byte[8192];
              while ( (bytesRead = stream.read(buffer, 0, 8192)) != -1) {
                bos.write(buffer, 0, bytesRead);//将文件写入服务器
              }
              bos.close();
              stream.close();
            }catch(Exception e){
              System.err.print(e);
            }
            //request.setAttribute("dat",file.getFileName());
            return mapping.findForward("display");
        }
        return null;
      }
    }
      

  2.   

    我是这么做的, 一般图片的话,file另存为 img + 相关的数据库table 的主键.
    这样的话,每个图片就是唯一的了。
    如果是电影的画就用文件夹分类应该好一些。
      

  3.   

    你的文件名有没有意义的,如果没有就用时间来作为图片的名称就OK了,如是有意义,可以参考fckeditor,他的文件上传后如果出现同名会这样改的
    如:fangbiao.txt ,就会改为fangbiao[1].txt,以此类推