例如:
.....
String filename = "filename.xls";
response.reset(); //1
//response.setHeader("Cache-Control", "no-store"); //2
//response.setHeader("Pragma", "no-store"); //3
response.setDateHeader("Expires", 0); //4response.setContentType("application/vnd.ms-excel");
response.setCharacterEncoding("utf-8");
response.setHeader("Content-disposition", "attachment;filename=" + filename);
InputStream is = new ByteArrayInputStream(baos.toByteArray());
OutputStream outputStream = response.getOutputStream();
int data = -1;
while ((data = is.read()) != -1) {
outputStream.write(data);
}
outputStream.flush();
outputStream.close();
.....
注意:
1.以上代码1必须写在2,3,4之前才能起效。
2.代码2,3两段需要删掉,要清楚缓存,只需要把让文件过期即可(即代码4)。