getOutputStream() has already been called for this response 异常问题
我的代码:
try {
BufferedInputStream br = new BufferedInputStream(new FileInputStream(f));
byte[] buf = new byte[1024];
int len = 0;
response.reset(); // 非常重要
// 纯下载方式
response.setContentType("application/zip");
if (flag) {// 非压缩
response.setHeader("Content-Disposition", "attachment; filename=" + exportName + ".csv");
} else {// 压缩
response.setHeader("Content-Disposition", "attachment; filename=" + exportName + ".zip");
}
OutputStream out = response.getOutputStream();
while ((len = br.read(buf)) > 0)
out.write(buf, 0, len);
out.flush();
br.close();
out.close();
} catch (Exception e) {
e.printStackTrace();
log.errorOther(null, e, LogErrorConstant.OTHER_UNKNOWN_ERROR);
}
return null;
网上很多网友说,在使用完输出流以后加入下面两行代码:
out.clear();
out = pageContext.pushBody();
但是我的是在Java中写的,不是JSP界面,是在Action中,有没有哪位大侠遇到过这种问题呢?