刚开始传图片的时候没有什么问题,当传个几十张之后图片就不能传上去了,服务器不报任何错误和异常,只是会在tmp文件夹里面有临时文件存在。我在保存文件的那个方法的开始和结尾处 执行 system.out.printlin("----------------"),都打印出来了,望高手解决

解决方案 »

  1.   

    看一下你上传的最大数量是多少勒,真不知道为什么打印出
    system.out.printlin( "---------------- 
    应该是在你的代码里面有这些吧,去看看这里
      

  2.   

    我的图片名称是用的数据库的主键ID,主键是用uu.hex生产的,肯定是唯一的,比如我上传的图片是262K大小,他会在tmp临时文件夹里有一个262K大小的临时文件,虽然图片上传不上去,系统的其他功能都能正常使用,有时候上传个70到80张就不行了,有时候传十几张就不行了,必须重启tomcat才能继续使用
      

  3.   

    重启tomcat,不会是内存溢出了吧,捕获下OutOfMemoryError 
          try {      }
          catch(OutOfMemoryError e) {
                 System.err.println/(e.getMessage());
          }
      

  4.   

    /**
     * 上传图片保存
     * 
     * @return
     */
    public String addPicInfo() {
    try {

    System.out.println("--------------1");

    PicInfo picInfo = new PicInfo();
    picInfo.setCreatetime(new Date());
    picInfo.setIntro(intro);
    picInfo.setPicname(picName);// PIC pic = new PIC(file);
    // String picPath = pic.save(getFileFileName(),webSiteId);

    String picPath = saveFile();

    //System.out.println(picPath);

    picInfo.setPath(picPath);
    picInfo.setWebSiteId(Long.valueOf(webSiteId));
    picService.save(picInfo);
    super.getRequest().setAttribute("picInfo", picInfo);
                            
                            System.out.println("--------------2");
    return super.SUCCESS;
    } catch (Exception e) {
    e.printStackTrace();
    return super.ERROR;
    }
    }
    private String saveFile(){
    //System.out.println(uploadFileFileName);
    BufferedOutputStream out = null;
    BufferedInputStream in = null;
    FileOutputStream fos = null;
    FileInputStream fis = null;

    try {

    if(getFileFileName().indexOf(".")!=-1)
    fileFileName = getFileFileName().substring(getFileFileName().lastIndexOf("."));

    String str = TimeFormater.formatNowTimetoString("yyyy-MM-dd");
    String[] temp = str.split("-");
    String tempPath1 =temp[0] + File.separator+temp[1] + File.separator + temp[2]+ File.separator;

                            //Util.createPK()会返回一个唯一主键ID,我用他做文件名称
    String subpath = tempPath1+ Util.createPK()+fileFileName;

    String vPath = Systemconfig.basePath+"ptl"+File.separator+webSiteId+File.separator+"upload"+File.separator +subpath;

    File folderFile = new File(Systemconfig.basePath+"ptl"+File.separator+webSiteId+File.separator+"upload"+File.separator +tempPath1);

    if(!folderFile.exists())
    folderFile.mkdirs();

    fos = new FileOutputStream(vPath);
    fis = new FileInputStream(getFile());

    out = new BufferedOutputStream(fos);
    in = new BufferedInputStream(fis); 

    int bytelength = (int)file.length();
        byte [] buffer = new byte [bytelength];
              
                while (in.read(buffer) > 0 )  {
                   out.write(buffer);
               } 
                in.close();
            out.close();
            fos.close();
            fis.close();
            
            subpath = subpath.replaceAll("\\\\", "/");
                return subpath;
    } catch (Exception e) {
    try{
     in.close();
             out.close();
             fos.close();
             fis.close();
    }catch(Exception ex){
    ex.printStackTrace();
    }
    e.printStackTrace();
      return "";
    }

    }
      

  5.   

    内存溢出的话会tomcat会报异常的,但是我其他功能都是正常的
      

  6.   

    大家帮我一起探讨一下看看有些什么可能性
    这个我也加过了
    <filter> 
            <filter-name> struts-cleanup </filter-name> 
            <filter-class> 
                org.apache.struts2.dispatcher.ActionContextCleanUp
            </filter-class> 
        </filter>