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=ComplaintsImportModel.xls");
String path = this.getClass().getClassLoader().getResource("/")//这里才是问题的关键,WebLogic服务器要在读取添加一个"/"
.getPath();
path = path.substring(1, path.length());
String name = File.separator + path + "ComplaintsImportModel.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);
}
}