以流的形式将文件写入页面,直接下载

try {

OutputStream out = response.getOutputStream();

response.reset();

response.setHeader("content-disposition",

"attachment;filename="+java.net.URLEncoder.encode(reportName,"UTF-8")+".xls");

response.setContentType("APPLICATION/msexcel");

wb.write(out);

out.close();

} catch (FileNotFoundException e) {

throw new DAOException("");

} catch (IOException e) {

throw new DAOException("");

 

}

原文地址:https://www.cnblogs.com/spiritualWindows/p/4325807.html