ReportDownload.jsp
1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<%@ page language="java" import="java.io.*,java.net.*,weaver.general.*"%><%String en_name = Util.null2String(request.getParameter("en_name")).trim();
String cn_name = Util.null2String(request.getParameter("cn_name"));
String en_type = Util.null2String(request.getParameter("en_type"));
String infofile = GCONST.getRootPath() +"filesystem"+ File.separatorChar +"templetecheck"+ File.separatorChar + en_name;
if("allfilereport".equals(en_name)){//全部文件检测报告
infofile=GCONST.getRootPath()+"system"+File.separatorChar+"upgradetoe9"+File.separatorChar+"report"+File.separatorChar+"templetecheckReport_all.zip";
cn_name = cn_name + ".zip";
} else if (en_type.equals("all")) {
cn_name = cn_name + ".zip";
infofile=infofile+".zip";
}else{
cn_name = cn_name + ".xls";
infofile=infofile+".xls";
}
try {
//获取文件路径
String filePath = "";
filePath = infofile;
//设置向浏览器端传送的文件格式
response.setContentType("application/vnd.ms-excel");
cn_name = URLEncoder.encode(cn_name, "UTF-8");
response.addHeader("Content-Disposition", "attachment;filename="+ cn_name);
FileInputStream fis = null;
OutputStream os = null;
try {
os = response.getOutputStream();
fis = new FileInputStream(filePath);
byte[] b = new byte[1024 * 10];
int i = 0;
while ((i = fis.read(b)) > 0) {
os.write(b, 0, i);
}
os.flush();
os.close();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (fis != null) {
try {
fis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (os != null) {
try {
os.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
%>