AreaImportHistoryLog.jsp
3.86 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<%@ page import="weaver.general.Util,weaver.file.*,java.util.*" %>
<%@ page import="java.text.SimpleDateFormat"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" %>
<%@page import="java.io.File"%>
<%@page import="java.io.BufferedInputStream"%>
<%@page import="java.io.FileInputStream"%>
<%@page import="java.io.OutputStream"%>
<%@page import="java.net.URLEncoder"%>
<%@page import="java.io.BufferedReader"%>
<%@page import="java.io.FileReader"%>
<jsp:useBean id="FileSecurityTool" class="weaver.hrm.common.FileSecurityTool" scope="page" ></jsp:useBean>
<%@ include file="/page/maint/common/initNoCache.jsp" %>
<%
//if (!HrmUserVarify.checkUserRight("HrmDefaultScheduleEdit:Edit",
// user)) {
// response.sendRedirect("/notice/noright.jsp");
// return;
//}
%>
<%!
//读取的日志文件根据修改时间进行排序
class CompratorByLastModified implements Comparator
{
public int compare(Object f1, Object f2) {
File file1=(File)f1;
File file2=(File)f2;
long diff = file1.lastModified()-file2.lastModified();
if(diff<0)
return 1;
else if(diff==0)
return 0;
else
return 0;
}
}
%>
<%
String option=request.getParameter("option");
if("downLoad".equals(option)){
String path = Util.null2String(request.getParameter("path"));
String securityFilePath = FileSecurityTool.get(path);
String filePath=securityFilePath;//request.getRealPath("/").replace("\\","/")+"/hrm/area/import/log/"+);
File file = new File(filePath);
if(file.exists() && file.isFile()){
try {
String fileName=filePath.substring(filePath.lastIndexOf("/")+1);
BufferedReader bis=new BufferedReader(new FileReader(filePath));
fileName =URLEncoder.encode(fileName, "UTF-8");// 处理中文文件名的问题
out.clear();
response.reset();
response.setContentType("application/x-msdownload");// 不同类型的文件对应不同的MIME类型
response.setCharacterEncoding("GBK");
response.setHeader("Content-Disposition",
"attachment; filename=" + fileName);
OutputStream os = response.getOutputStream();
String str="";
while ((str=bis.readLine())!=null){
os.write((str+"\r\n").getBytes());
}
bis.close();
os.flush();
os.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}else if("delete".equals(option)){
String filePath=request.getParameter("path");
filePath = FileSecurityTool.get(filePath);
File file = new File(filePath);
if(file.exists() && file.isFile()){
out.print(file.delete());
}
}else{
String filePath=request.getRealPath("/").replace("\\","/")+"hrm/area/import/log";
File logFile=new File(filePath);
if (!logFile.exists()) {
logFile.mkdir();
}
File logList[]=logFile.listFiles();
Arrays.sort(logList,new CompratorByLastModified());
%>
<%
SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
for(int i=0;i<logList.length;i++){
String oriPath = filePath+"/"+logList[i].getName();
String md5Path = FileSecurityTool.put(oriPath);
%>
<TR <%if(i%2==0) out.print("class=datalight"); else out.print("class=datadark");%>>
<td><%=dateFormat.format(new Date(logList[i].lastModified()))%></td>
<td><%=logList[i].getName()%></td>
<td>
<a href="#" onclick="downLoadLog('<%=md5Path%>')"><%=SystemEnv.getHtmlLabelName(258,user.getLanguage())%></a>
</td>
<td>
<a href="#" onclick="deleteLog('<%=md5Path%>',this)"><%=SystemEnv.getHtmlLabelName(23777,user.getLanguage())%></a>
</td>
</TR>
<%
}
%>
<script type="text/javascript">callback('log');</script>
<%} %>