解决weblogic下报java.net.ProtocolException: Exceeded stated content-length of异常问题

来源:互联网 发布:微博刷赞软件手机版 编辑:程序博客网 时间:2024/05/28 05:17

今天在做文件下载时出现如何错误:

java.net.ProtocolException: Exceeded stated content-length of: '19456' bytes

我的程序代码是:


  
   response.setContentType("application/octet-stream");

   response.setHeader("Content-Disposition",
       "attachment;filename=/"" + StringI18.u2a(fileName)
       + "/"");
   response.setContentLength((int) fileis.size);


   
   
   ServletOutputStream sos = response.getOutputStream();
   byte buffer[] = new byte[1024];
   int b=0;
   while ((b = fileis.inputStream.read(buffer)) != -1) {
    sos.write(buffer, 0, b);
   }
   sos.flush();
   fileis.inputStream.close();
   if(fileis.sourceInputStream!=null){
    fileis.sourceInputStream.close();
   }
   sos.close();

 

经多方查证,主要是因为在weblogic下需要response.reset();

 

原创粉丝点击