下载模板
public void importSuccess() throws Exception {
try{
HttpServletResponse response = Struts2Utils.getResponse();
//重置响应
response.reset();
//设置响应头为二进制流
response.setContentType( "application/x-msdownload;charset=utf-8");
response.setContentType("APPLICATION/OCTET-STREAM ");
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition", "attachment; filename=Fxcustomer.xls");
String path = this.getClass().getClassLoader().getResource("/").getPath();
path=path.substring(1,path.length());
String name = File.separator+path+"Fxcustomer.xls";
logger.info("**********************************"+name+"*******************************");
InputStream is = new FileInputStream(name);
HSSFWorkbook wb = new HSSFWorkbook(is);
//得到 文件流
OutputStream out = response.getOutputStream();
wb.write(out);
is.close();
out.flush();
out.close();
} catch (Exception e) {
logger.error("下载导出模版失败",e);
}
}
public void importSuccess() throws Exception {
try{
HttpServletResponse response = Struts2Utils.getResponse();
//重置响应
response.reset();
//设置响应头为二进制流
response.setContentType( "application/x-msdownload;charset=utf-8");
response.setContentType("APPLICATION/OCTET-STREAM ");
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition", "attachment; filename=Fxcustomer.xls");
String path = this.getClass().getClassLoader().getResource("/").getPath();
path=path.substring(1,path.length());
String name = File.separator+path+"Fxcustomer.xls";
logger.info("**********************************"+name+"*******************************");
InputStream is = new FileInputStream(name);
HSSFWorkbook wb = new HSSFWorkbook(is);
//得到 文件流
OutputStream out = response.getOutputStream();
wb.write(out);
is.close();
out.flush();
out.close();
} catch (Exception e) {
logger.error("下载导出模版失败",e);
}
}