随笔-8  评论-8  文章-10  trackbacks-0
//加入这2句
out.clear();
out=pageContext.pushBody();

response.setHeader("Pragma","No-cache");
response.setHeader("Cache-Control","no-cache");
response.setDateHeader("Expires", 0);




每天进步一点点

posted on 2008-10-24 14:52 应越 阅读(1032) 评论(2)  编辑  收藏

评论:
# re: getOutputStream() has already been called for this response 的解决方法 2009-08-21 20:42 | 蓝鱼
受用了!!  回复  更多评论
  
# re: getOutputStream() has already been called for this response 的解决方法 2010-06-02 15:23 | 007
try {
//创建一个带有路径的文件
File f = new File(fileDiskURL+fileName);//getDataExtractPath()

//创建一个与文件对应的输入流
FileInputStream in = new FileInputStream(f);
//得到一个响应,并对响应进行各种设置
HttpServletResponse response = ServletActionContext.getResponse();
response.setContentType("application/octet-stream");
response.setHeader("Content-Disposition", "attachment; filename=" + new String(fileName.getBytes("ISO-8859-1"),"GBK"));
//fetch the file
// OutputStream op = response.getOutputStream();
// byte[] buf = new byte[in.available()];
// in.read(buf);
// op.write(buf);
// in.close();
// op.flush();
// op.close();
System.out.println("aaaaaaaaaaa11111111111aaaaaaaaaaaaaa");
int length = (int) f.length();
if (length != 0) {
byte[] buf = new byte[4096];
OutputStream op = response.getOutputStream();
//把ServletOutputStream 换成 java.io里的outputstream就可以了
//ServletOutputStream op = response.getOutputStream();
while ((in != null) && ((length = in.read(buf)) != -1)) {
op.write(buf, 0, length);
}
in.close();
op.flush();
op.close();
}
return true;
} catch (FileNotFoundException e) {
e.printStackTrace();
return false;
} catch (IOException e) {
e.printStackTrace();
return false;
}  回复  更多评论
  

只有注册用户登录后才能发表评论。


网站导航: