// 浏览器下载excel模板
public void downloadTemplate(HttpServletResponse response,HttpServletRequest request) throws Exception {
String fileName="导出模板.xls";
response.reset();
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, "utf-8"));
String filePath=request.getServletContext().getRealPath("/excel/")+fileName;
FileInputStream input=new FileInputStream(filePath);
OutputStream out=response.getOutputStream();
byte[] b=new byte[2048];
int len;
while((len=input.read(b))!=-1) {
out.write(b,0,len);
}
response.setHeader("Content-Length", String.valueOf(input.getChannel().size()));
input.close();
}
网友评论