这是什么原因呢?
请看我的原始代码:
只要加上
就OK了
请看我的原始代码:
if(!StringUtils.isEmpty(name)){
try{
String disposition = "attachment;filename="
+ new String(name.getBytes("gb2312"),"iso-8859-1")
+ "."+suffix;
response.addHeader("Content-disposition", disposition);
response.addHeader("Content-Length", String.valueOf(attachFile.length()));
in = FileUtils.openInputStream(attachFile);
ou = response.getOutputStream();
IOUtils.copy(in,ou);
}catch(Exception e){
e.printStackTrace();
}finally{
IOUtils.closeQuietly(in);
IOUtils.closeQuietly(ou);
}
}只要加上
response.setHeader("Connection", "close");就OK了
本文探讨了在处理文件下载时遇到的头设置问题,并提供了解决方案,通过添加Connection:close来确保浏览器正确关闭连接。
1098

被折叠的 条评论
为什么被折叠?



