public void downLoad(HttpServletRequest request,HttpServletResponse response, boolean isOnLine) throws Exception {
String fileName = "ODS报表系统指标地图.xlsx";
String path2 = File.separator+"WEB-INF"+File.separator+"PICC-File.xlsx";
InputStream path = request.getSession().getServletContext().getResourceAsStream(path2);
String ext = fileName.substring(fileName.lastIndexOf(".") + 1);
String agent = (String) request.getHeader("USER-AGENT");
try {
if (agent != null && agent.indexOf("Firefox") != -1) {
fileName = new String(fileName.getBytes("UTF-8"), "iso-8859-1");
} else {
fileName = URLEncoder.encode(fileName, "UTF-8");
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
BufferedInputStream bis = null;
OutputStream os = null;
response.reset();
response.setCharacterEncoding("utf-8");
if ("xlsx".equals(ext)) {
response.setContentType("application/xlsx");
} else if ("doc".equals(ext)) {
response.setContentType("application/msword");
}else if (ext == "pdf") {
response.setContentType("application/pdf");
}
response.setHeader("Content-Disposition", "attachment; filename=" + fileName);
try {
bis = new BufferedInputStream(path);
byte[] b = new byte[bis.available() + 1000];
int i = 0;
os = response.getOutputStream();
while ((i = bis.read(b)) != -1) {
os.write(b, 0, i);
}
os.flush();
os.close();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (os != null) {
try {
os.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}