一、
String filePath = currentUser.getRealName()+"员工离职统计表.xls";// 文件路径
FileOutputStream fout = new FileOutputStream(filePath);
wb.write(fout);// 保存Excel文件
fout.close();// 关闭文件流
InputStream is = new FileInputStream(new File(filePath));
OutputStream os = response.getOutputStream();// 得到向客户端输出二进制数据的对象
response.setHeader("Content-Disposition", "attachment;filename="
+ new String(filePath.getBytes("gb2312"), "iso8859-1"));
response.setCharacterEncoding("utf-8");
int j = 0;
byte[] b = new byte[8192];
while ((j = is.read(b, 0, 8192)) != -1) {
os.write(b, 0, j);
}
// os.flush();
is.close();
os.close();
二、
// 创建文件
String downloadPath = "/download/resumeJobRecord_by"+currentUser.getCompany().getId()+".xls";
FileOutputStream out = new FileOutputStream(request.getSession().getServletContext().getRealPath("")+
downloadPath);
wb.write(out);
out.close();
//下载
ActionForward forward = new ActionForward(); // return value
forward.setPath(downloadPath);
forward.setRedirect(true);
return (forward);