刚开始传图片的时候没有什么问题,当传个几十张之后图片就不能传上去了,服务器不报任何错误和异常,tomcat的log里面也没有错误信息,只是会在tmp文件夹里面有临时文件存在。访问保存图片这个方法的时候好像也不执行,但是我的系统的其他功能都能正常使用,就只有图片上传这个方法不执行, 如下就是我图片上传这个方法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;

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 [255];
          
            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 "";
}

}

解决方案 »

  1.   

    struts2文件上传
      

  2.   

    folderFile.mkdirs();这句执行了才生成临时文件夹,从这里开始debug跟踪一下Ps(既然执行到了上面的语句,我认为System.out.println(uploadFileFileName);这句打不出来很费解,这里你也可以设个断点跟踪一下)
      

  3.   

    应该代码有错误吧,调试一下,主要是for循环的那个地方祝楼主好运
      

  4.   

    一下代码是我做上传的一个例子,你可以参照一下:html代码:<input type="file" name="file" id="imgurl" style="border:1px solid #7F9DB9;"/>
    action代码:// ********************************************************
                //首先将文件写入一个输入流里面
                InputStream is = new FileInputStream(file);
                //其次得到你要上传文件到那个目录
                String root = ServletActionContext.getRequest().getRealPath("/upload/images");
                DateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
                String formatDate = format.format(new Date());
                int random = new Random().nextInt(10000);
                int position = fileFileName.indexOf(".");
                String extension = fileFileName.substring(position) ;
                String newFileName = formatDate + random + extension ;
                //再次创建一个File来保存你的文件
                File destFile = new File(root,newFileName);
                //然后就是一个输出流将文件写入到File中。
                OutputStream os = new FileOutputStream(destFile);
                //以下就是写入文件的方式
                byte buffer[] = new byte[2048]; 
                int length = 0;
                while((length = is.read(buffer))>0){
                    os.write(buffer,0,length);
                }
                //最后一定要关闭流 
                is.close();
                os.close();