日期:2014-05-17  浏览次数:20710 次

servlet中response.setHeader("Content-Disposition", "attachment;Filename=..")下载问题
                response.setContentType("text/html");
                //(换成response.setContentType("image/jpeg");也不行)

response.setHeader("Content-Disposition", "attachment;Filename=011.jpg");
String path=this.getServletContext().getRealPath("/file/011.jpg");

FileInputStream fis=new FileInputStream(path);
System.out.println(path);
int len=0;
byte buffer[]=new byte[1024];

OutputStream os=response.getOutputStream();
while((len=fis.read())>0){
os.write(buffer, 0, len);
}
os.close();
fis.close();
图片大小有几十K,弹出下载框的时候变成了几百B,换了几个文件试了下还是一样,文件变得很小,下载之后打不开
Servlet Content-Disposition 下载大小出错

------解决方案--------------------
你的fis根本就没读到buffer去