你可能没有关闭stream吧,把代码贴出来看看

解决方案 »

  1.   

    是这样的,我先编写了个上传程序在tomcat的webapps/demo下运行,完全没问题.
    后来由于项目需要,对服务器的上的iis和tomcat进行了整合,之后在把整个站点文件放在d:\wwwweb目录下.这是其他文件没问题,但是多个上传出错了.我还注意到一点,当上传多张只有几K大的gif文件时候不会有问题,传100多K的jpg文件就不能完成,报的错就是上面我留下的.
    下面是该文件的源码:<%@ page contentType="text/html; charset=gb2312" language="java"%>
    <%@ page import="java.util.*,java.io.*,org.apache.commons.fileupload.*,java.util.regex.Matcher,java.util.regex.Pattern" %>
    <%@ page session="true" buffer="24kb" autoFlush="true" %>
    <%Date datename=new java.util.Date();
      DiskFileUpload fu = new DiskFileUpload(); fu.setSizeMax(10*1024*1024); fu.setSizeThreshold(4096);
     
     fu.setRepositoryPath("C:\\printtemp");
     List fileItems = fu.parseRequest(request);
     
      Iterator iter = fileItems.iterator();  
       String regExp=".+\\\\(.+)$";
       int j=1;
       int photonum=0;
       String tempphotoname="";
       boolean allow=false;
    //过滤掉的文件类型
      String[] errorType={".exe",".com",".cgi",".asp"};
      String[] allowType={".jpg",".gif",".bmp",".JPG","GIF","BMP"};
       Pattern p = Pattern.compile(regExp);
          while (iter.hasNext()) {
           FileItem item = (FileItem)iter.next();
           if (!item.isFormField()) {
               String name = item.getName();
               long size = item.getSize();
               if((name==null||name.equals("")) && size==0)
                   continue;
            Matcher m = p.matcher(name);
           boolean result = m.find();
           if (result){
               for (int temp=0;temp<errorType.length;temp++){
               if (m.group(1).endsWith(errorType[temp])){
         allow=false;
                     throw new IOException(name+": wrong type");
               }
               }
         }
     String photoname=Integer.toString(datename.getYear())+Integer.toString(datename.getMonth())+Integer.toString(datename.getDate())+Integer.toString(datename.getHours())+Integer.toString(datename.getMinutes())+Integer.toString(datename.getSeconds());
      Random r = new Random();
        String random = String.valueOf(Math.abs(r.nextInt())).substring(0,4);
    photoname=photoname+random+Integer.toString(j);
    String day=Integer.toString(datename.getYear()+1900)+Integer.toString(datename.getMonth()+1)+Integer.toString(datename.getDate());
     if(allow){
     item.write(new File("D:\\print.139sc.com\\userPhotos\\"+day+"\\"+photoname+fileext));
                              }
     else
     {
     out.print("<script>alert('上传文件类型不正确');history.back(-1);</script>");
     out.close();
     }
               }
            }
           }
    %>部分代码省略.