-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.jsp
More file actions
189 lines (174 loc) · 5.67 KB
/
index.jsp
File metadata and controls
189 lines (174 loc) · 5.67 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="java.io.*,java.util.*,java.util.regex.*,java.text.*,org.apache.commons.lang3.*,java.net.URLDecoder" %>
<%@ page import="xyz.wystudio.jsp.config.*" %>
<%@ page import="xyz.wystudio.jsp.bean.*" %>
<%@ page import="xyz.wystudio.jsp.util.*" %>
<%!
public String folder;
public String sort;
public boolean isasc = true;
public String asc;
public String getTh(String width, String folder2, String sort, boolean isasc2, String name){
if(isasc2){
return "<th style=\"width:" + width + "%\"><a href=\"./?folder=" + folder2 + "&sort=" + sort + "&isasc=0\">" + name + "</a></th>";
}else{
return "<th style=\"width:" + width + "%\"><a href=\"./?folder=" + folder2 + "&sort=" + sort + "&isasc=1\">" + name + "</a></th>";
}
}
%>
<%
String path = application.getRealPath(request.getRequestURI());
String repath = request.getRequestURI();
// 创建一个站点配置实例,并加载站点配置信息
SiteConfig siteConfig = new SiteConfig();
siteConfig.load(path);
FileList fileList = new FileList();
sort = request.getParameter("sort");
folder = request.getParameter("folder");
asc = request.getParameter("isasc");
if(sort == null){
sort = "name";
}
if(asc != null){
isasc = asc.equals("1");
}
if (folder != null) {
folder = URLDecoder.decode(folder, "utf-8");
File folderFile = new File(path + "files" + folder);
if (!folderFile.exists()) {
response.sendRedirect("404.jsp");
return;
}
for(String str : siteConfig.getExcludeByDirector()){
if (folder.equals("/" + str)){
response.sendRedirect("404.jsp");
return;
}
}
}else{
folder = "";
}
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title><%=siteConfig.getSiteName()%></title>
<link rel="stylesheet" href="https://unpkg.com/mdui@1.0.2/dist/css/mdui.min.css" />
<%@include file="./include/header.html"%>
<style>
.container {
width: 80%;
margin: 10% auto 0;
background-color: #f0f0f0;
padding: 2% 5%;
border-radius: 10px;
}
.div-footer{
height: 130px;
}
.p-footer{
color: #888888;
text-align: center;
}
ul {
padding-left: 20px;
}
ul li {
line-height: 2.3;
}
a {
color: #20a53a;
text-decoration:none;
}
</style>
<script src="https://unpkg.com/mdui@1.0.2/dist/js/mdui.min.js"></script>
</head>
<body id="v1">
<div id="v2" class="container">
<h1 id="v3"><%=siteConfig.getSiteName()%></h1>
<h3 id="v4"><%=siteConfig.getSiteDescription()%></h3>
<br/>
<table id="list" class="mdui-table mdui-color-transparent">
<thead>
<tr>
<%
String nameAscTh = getTh("55",folder,"name",true,"文件名称 ↑");
String nameDescTh = getTh("55",folder,"name",false,"文件名称 ↓");
String sizeAscTh = getTh("20",folder,"size",true,"大小 ↑");
String sizeDescTh = getTh("20",folder,"size",false,"大小 ↓");
String timeAscTh = getTh("25",folder,"time",true,"日期 ↑");
String timeDescTh = getTh("25",folder,"time",false,"日期 ↓");
switch(sort){
case "name":
if(isasc){
out.println(nameAscTh);
}else{
out.println(nameDescTh);
}
out.println(sizeAscTh);
out.println(timeAscTh);
break;
case "size":
out.println(nameAscTh);
if(isasc){
out.println(sizeAscTh);
}else{
out.println(sizeDescTh);
}
out.println(timeAscTh);
break;
case "time":
out.println(nameAscTh);
out.println(sizeAscTh);
if(isasc){
out.println(timeAscTh);
}else{
out.println(timeDescTh);
}
break;
default:
out.println(nameAscTh);
out.println(sizeAscTh);
out.println(timeAscTh);
break;
}
%>
</tr>
</thead>
<tbody>
<%
out.print("<p>当前路径:/<a href=\"./\">根目录</a>" + (folder != null ? folder : "") + "</p>\n");
fileList.load(path + "files" + (folder != null ? folder : ""),siteConfig);
FileBean[] filrBeans = fileList.getFileBeans(sort,isasc);
if (filrBeans.length != 0) {
for (FileBean file : filrBeans) {
String name = file.getName();
String time = file.getTime();
String size = file.getSize();
if (file.isFolder()) {
String pathDir = (folder == null ? "" : folder) + "/" + name;
out.println("<tr>");
out.println("<td class=\"link\"><a href=\"./?folder=" + pathDir + "\"><i class=\"mdui-icon material-icons\"></i> " + name + "/</a></td>");
out.println("<td class=\"size\">-</td>");
out.println("<td class=\"date\">" + time + "</td>");
out.println("</tr>");
} else {
String pathFile = "files" + (folder != null ? folder : "") + "/" + name;
out.println("<tr>");
out.println("<td class=\"link\"><a href=\"" + pathFile + "\"><i class=\"mdui-icon material-icons\"></i>" + name + "</a></td>");
out.println("<td class=\"size\">" + size + "</td>");
out.println("<td class=\"date\">" + time + "</td>");
out.println("</tr>");
}
}
}
%>
</tbody>
</table>
</br>
<%@include file="./include/footer.html"%>
</div>
</body>
</html>