├── .idea
├── .gitignore
├── artifacts
│ └── web_war_exploded.xml
├── copyright
│ └── profiles_settings.xml
├── description.html
├── encodings.xml
├── inspectionProfiles
│ └── Project_Default.xml
├── libraries
│ └── org_json_chargebee_1_0.xml
├── misc.xml
├── modules.xml
├── project-template.xml
├── scopes
│ └── scope_settings.xml
├── smartfox_info.xml
└── uiDesigner.xml
├── README.md
├── img
├── ui.png
└── 网盘.vsdx
├── netdisc.iml
├── out
├── artifacts
│ └── web_war_exploded
│ │ ├── WEB-INF
│ │ ├── classes
│ │ │ ├── API
│ │ │ │ ├── DelUsername.class
│ │ │ │ ├── GetFileList.class
│ │ │ │ └── GetUsername.class
│ │ │ ├── Model
│ │ │ │ ├── DBUtil.class
│ │ │ │ ├── FileDownload.class
│ │ │ │ └── FileUpload.class
│ │ │ ├── Utils
│ │ │ │ ├── Authentication.class
│ │ │ │ └── Encoder.class
│ │ │ ├── filters
│ │ │ │ ├── EncodeFilter.class
│ │ │ │ └── Filter.class
│ │ │ └── user
│ │ │ │ ├── LoginController.class
│ │ │ │ └── RegisterController.class
│ │ └── web.xml
│ │ ├── disc.html
│ │ ├── getUser.js
│ │ ├── info
│ │ ├── about.html
│ │ ├── money.html
│ │ └── techSupport.html
│ │ ├── style.css
│ │ └── user
│ │ ├── login.html
│ │ └── register.html
└── production
│ └── netdisc
│ ├── API
│ ├── DelUsername.class
│ ├── GetFileList.class
│ └── GetUsername.class
│ ├── Model
│ ├── DbUtil.class
│ ├── FileDownload.class
│ └── FileUpload.class
│ ├── Utils
│ ├── Authentication.class
│ └── Encoder.class
│ ├── filters
│ ├── EncodeFilter.class
│ └── Filter.class
│ └── user
│ ├── LoginController.class
│ └── RegisterController.class
├── src
├── API
│ ├── DelUsername.java
│ ├── GetFileList.java
│ └── GetUsername.java
├── Model
│ ├── DBUtil.java
│ ├── FileDownload.java
│ └── FileUpload.java
├── Utils
│ ├── Authentication.java
│ └── Encoder.java
├── filters
│ ├── EncodeFilter.java
│ └── Filter.java
└── user
│ ├── LoginController.java
│ └── RegisterController.java
└── web
├── WEB-INF
└── web.xml
├── disc.html
├── getUser.js
├── info
├── about.html
├── money.html
└── techSupport.html
├── style.css
└── user
├── login.html
└── register.html
/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /workspace.xml
--------------------------------------------------------------------------------
/.idea/artifacts/web_war_exploded.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | $PROJECT_DIR$/out/artifacts/web_war_exploded
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/.idea/description.html:
--------------------------------------------------------------------------------
1 | Minimal Java Enterprise Web project.
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/inspectionProfiles/Project_Default.xml:
--------------------------------------------------------------------------------
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 |
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 |
--------------------------------------------------------------------------------
/.idea/libraries/org_json_chargebee_1_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
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 | Class structure
49 |
50 |
51 | Declaration redundancy
52 |
53 |
54 | Google Web Toolkit issues
55 |
56 |
57 | Inheritance issues
58 |
59 |
60 | Javadoc issues
61 |
62 |
63 | TestNG
64 |
65 |
66 |
67 |
68 | JavaDoc
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 | dom4jrrrrr
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 | 1.6
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 | 1.6
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.idea/project-template.xml:
--------------------------------------------------------------------------------
1 |
2 | WEB_XML_VERSION
3 | IJ_APPLICATION_SERVER
4 | /javaee/webModule.png
5 | app-server
6 |
7 |
--------------------------------------------------------------------------------
/.idea/scopes/scope_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/.idea/smartfox_info.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/uiDesigner.xml:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Netdisc
2 | 基于javaWeb原生servlet开发的网盘项目
3 | ***
4 | 技术栈:servlet+Mysql+原生js
5 |
6 |
7 |
8 |
9 |
10 | ## 功能模块
11 |
12 | * [x] 用户模块
13 | * [x] 文件上传
14 | * [x] 网盘文件列表
15 | * [x] 文件预览
16 | * [x] 文件下载
17 |
18 | > 只写了基本的功能,不知道什么时候有时间完善下
19 | >
20 | > 可以拿走,喜欢的同学欢迎star~
21 |
22 |
23 |
24 | 
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/img/ui.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RanchoTuring/Netdisk/2058810f049374797448214b0358fee58cad006e/img/ui.png
--------------------------------------------------------------------------------
/img/网盘.vsdx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RanchoTuring/Netdisk/2058810f049374797448214b0358fee58cad006e/img/网盘.vsdx
--------------------------------------------------------------------------------
/netdisc.iml:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/out/artifacts/web_war_exploded/WEB-INF/classes/API/DelUsername.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RanchoTuring/Netdisk/2058810f049374797448214b0358fee58cad006e/out/artifacts/web_war_exploded/WEB-INF/classes/API/DelUsername.class
--------------------------------------------------------------------------------
/out/artifacts/web_war_exploded/WEB-INF/classes/API/GetFileList.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RanchoTuring/Netdisk/2058810f049374797448214b0358fee58cad006e/out/artifacts/web_war_exploded/WEB-INF/classes/API/GetFileList.class
--------------------------------------------------------------------------------
/out/artifacts/web_war_exploded/WEB-INF/classes/API/GetUsername.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RanchoTuring/Netdisk/2058810f049374797448214b0358fee58cad006e/out/artifacts/web_war_exploded/WEB-INF/classes/API/GetUsername.class
--------------------------------------------------------------------------------
/out/artifacts/web_war_exploded/WEB-INF/classes/Model/DBUtil.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RanchoTuring/Netdisk/2058810f049374797448214b0358fee58cad006e/out/artifacts/web_war_exploded/WEB-INF/classes/Model/DBUtil.class
--------------------------------------------------------------------------------
/out/artifacts/web_war_exploded/WEB-INF/classes/Model/FileDownload.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RanchoTuring/Netdisk/2058810f049374797448214b0358fee58cad006e/out/artifacts/web_war_exploded/WEB-INF/classes/Model/FileDownload.class
--------------------------------------------------------------------------------
/out/artifacts/web_war_exploded/WEB-INF/classes/Model/FileUpload.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RanchoTuring/Netdisk/2058810f049374797448214b0358fee58cad006e/out/artifacts/web_war_exploded/WEB-INF/classes/Model/FileUpload.class
--------------------------------------------------------------------------------
/out/artifacts/web_war_exploded/WEB-INF/classes/Utils/Authentication.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RanchoTuring/Netdisk/2058810f049374797448214b0358fee58cad006e/out/artifacts/web_war_exploded/WEB-INF/classes/Utils/Authentication.class
--------------------------------------------------------------------------------
/out/artifacts/web_war_exploded/WEB-INF/classes/Utils/Encoder.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RanchoTuring/Netdisk/2058810f049374797448214b0358fee58cad006e/out/artifacts/web_war_exploded/WEB-INF/classes/Utils/Encoder.class
--------------------------------------------------------------------------------
/out/artifacts/web_war_exploded/WEB-INF/classes/filters/EncodeFilter.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RanchoTuring/Netdisk/2058810f049374797448214b0358fee58cad006e/out/artifacts/web_war_exploded/WEB-INF/classes/filters/EncodeFilter.class
--------------------------------------------------------------------------------
/out/artifacts/web_war_exploded/WEB-INF/classes/filters/Filter.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RanchoTuring/Netdisk/2058810f049374797448214b0358fee58cad006e/out/artifacts/web_war_exploded/WEB-INF/classes/filters/Filter.class
--------------------------------------------------------------------------------
/out/artifacts/web_war_exploded/WEB-INF/classes/user/LoginController.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RanchoTuring/Netdisk/2058810f049374797448214b0358fee58cad006e/out/artifacts/web_war_exploded/WEB-INF/classes/user/LoginController.class
--------------------------------------------------------------------------------
/out/artifacts/web_war_exploded/WEB-INF/classes/user/RegisterController.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RanchoTuring/Netdisk/2058810f049374797448214b0358fee58cad006e/out/artifacts/web_war_exploded/WEB-INF/classes/user/RegisterController.class
--------------------------------------------------------------------------------
/out/artifacts/web_war_exploded/WEB-INF/web.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
--------------------------------------------------------------------------------
/out/artifacts/web_war_exploded/disc.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
2 |
3 |
4 |
5 | about
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/out/artifacts/web_war_exploded/info/money.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | money
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/out/artifacts/web_war_exploded/info/techSupport.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | techSupport
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/out/artifacts/web_war_exploded/style.css:
--------------------------------------------------------------------------------
1 | .menu {
2 | display: flex;
3 | width: 100%;
4 | background: #1e272e;
5 | }
6 |
7 | .logo {
8 | flex: auto;
9 | font-size: 30px;
10 | padding: 10px 50px;
11 | color: white;
12 | }
13 |
14 | .menuItems {
15 | flex: auto;
16 | justify-content: flex-end;
17 | display: flex;
18 | }
19 |
20 | .menuItem:hover {
21 | background: #ff3f34;
22 | cursor: pointer;
23 | }
24 |
25 | .menuItem {
26 | font-size: 20px;
27 | font-weight: lighter;
28 | text-decoration: none;
29 | color: white;
30 | padding: 20px 50px;
31 | }
32 |
33 | body {
34 | background-image: url("https://pan.baidu.com/static/images/16new/bg3.jpg");
35 | background-size: cover;
36 | background-position-y: 65px;
37 | margin: 0;
38 | font-family: "Microsoft YaHei UI";
39 | }
40 |
41 | .card {
42 | position: absolute;
43 | top: 50%;
44 | left: 70%;
45 | transform: translate(-50%, -50%);
46 | background: white;
47 | border-radius: 10px;
48 | box-shadow: #111111 1px 1px 10px;
49 | overflow: hidden;
50 | }
51 |
52 | .content:before {
53 | content: "“";
54 | color: #d2dae2;
55 | font-size: 70px;
56 | font-weight: bold;
57 | }
58 |
59 | .content {
60 | color: white;
61 | position: absolute;
62 | top: 50%;
63 | left: 15%;
64 | font-size: 50px;
65 |
66 | }
67 |
68 | .content:after {
69 | content: "”";
70 | color: #d2dae2;
71 | font-size: 70px;
72 | font-weight: bold;
73 | }
74 |
75 | form {
76 | margin: 30px 30px 0;
77 | }
78 |
79 | .title {
80 | justify-content: center;
81 | font-size: 25px;
82 | font-weight: bold;
83 | display: flex;
84 | margin: 0 auto 25px;
85 | }
86 |
87 | input[type="text"], input[type="password"] {
88 | display: block;
89 | font-size: 15px;
90 | width: 300px;
91 | padding: 14px 10px;
92 | outline: none;
93 | border: solid 1px #d2dae2;
94 | text-align: left;
95 | margin: 5px 0;
96 | }
97 |
98 | .remember {
99 | display: block;
100 | font-size: 13px;
101 | margin: 15px 0;
102 | }
103 |
104 | input[type="submit"] {
105 | display: block;
106 | padding: 12px 140px;
107 | border-radius: 5px;
108 | font-size: 15px;
109 | outline: none;
110 | border: none;
111 | cursor: pointer;
112 | background: #0fbcf9;
113 | color: white;
114 | margin: auto;
115 | }
116 |
117 | .function {
118 | margin: 20px 0 0;
119 | background: rgba(213, 233, 250, 0.58);
120 | padding: 20px;
121 | }
122 |
123 | .funcItem {
124 | font-size: 17px;
125 | font-weight: lighter;
126 | text-decoration: none;
127 | padding: 40px;
128 | color: #0fbcf9;
129 | }
--------------------------------------------------------------------------------
/out/artifacts/web_war_exploded/user/login.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | 在线网盘
7 |
8 |
9 |
10 |
20 | 多端并用
数据随身携带
21 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/out/artifacts/web_war_exploded/user/register.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | 用户注册
6 |
7 |
8 |
9 |
19 | 多端并用
数据随身携带
20 |
21 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/out/production/netdisc/API/DelUsername.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RanchoTuring/Netdisk/2058810f049374797448214b0358fee58cad006e/out/production/netdisc/API/DelUsername.class
--------------------------------------------------------------------------------
/out/production/netdisc/API/GetFileList.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RanchoTuring/Netdisk/2058810f049374797448214b0358fee58cad006e/out/production/netdisc/API/GetFileList.class
--------------------------------------------------------------------------------
/out/production/netdisc/API/GetUsername.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RanchoTuring/Netdisk/2058810f049374797448214b0358fee58cad006e/out/production/netdisc/API/GetUsername.class
--------------------------------------------------------------------------------
/out/production/netdisc/Model/DbUtil.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RanchoTuring/Netdisk/2058810f049374797448214b0358fee58cad006e/out/production/netdisc/Model/DbUtil.class
--------------------------------------------------------------------------------
/out/production/netdisc/Model/FileDownload.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RanchoTuring/Netdisk/2058810f049374797448214b0358fee58cad006e/out/production/netdisc/Model/FileDownload.class
--------------------------------------------------------------------------------
/out/production/netdisc/Model/FileUpload.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RanchoTuring/Netdisk/2058810f049374797448214b0358fee58cad006e/out/production/netdisc/Model/FileUpload.class
--------------------------------------------------------------------------------
/out/production/netdisc/Utils/Authentication.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RanchoTuring/Netdisk/2058810f049374797448214b0358fee58cad006e/out/production/netdisc/Utils/Authentication.class
--------------------------------------------------------------------------------
/out/production/netdisc/Utils/Encoder.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RanchoTuring/Netdisk/2058810f049374797448214b0358fee58cad006e/out/production/netdisc/Utils/Encoder.class
--------------------------------------------------------------------------------
/out/production/netdisc/filters/EncodeFilter.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RanchoTuring/Netdisk/2058810f049374797448214b0358fee58cad006e/out/production/netdisc/filters/EncodeFilter.class
--------------------------------------------------------------------------------
/out/production/netdisc/filters/Filter.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RanchoTuring/Netdisk/2058810f049374797448214b0358fee58cad006e/out/production/netdisc/filters/Filter.class
--------------------------------------------------------------------------------
/out/production/netdisc/user/LoginController.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RanchoTuring/Netdisk/2058810f049374797448214b0358fee58cad006e/out/production/netdisc/user/LoginController.class
--------------------------------------------------------------------------------
/out/production/netdisc/user/RegisterController.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RanchoTuring/Netdisk/2058810f049374797448214b0358fee58cad006e/out/production/netdisc/user/RegisterController.class
--------------------------------------------------------------------------------
/src/API/DelUsername.java:
--------------------------------------------------------------------------------
1 | package api;
2 |
3 | import utils.Authentication;
4 |
5 | import javax.servlet.ServletException;
6 | import javax.servlet.annotation.WebServlet;
7 | import javax.servlet.http.HttpServlet;
8 | import javax.servlet.http.HttpServletRequest;
9 | import javax.servlet.http.HttpServletResponse;
10 | import java.io.IOException;
11 |
12 | /**
13 | * 用户退出登录的功能接口
14 | *
15 | */
16 |
17 | @WebServlet(name = "DelUsername",urlPatterns = "/delUsername")
18 | public class DelUsername extends HttpServlet {
19 |
20 | /**
21 | * 接收 用户名 参数,与会话中保存的用户名对比
22 | * 两者一致时,销毁会话对象,退出登录
23 | * @param request
24 | * @param response
25 | * @throws ServletException
26 | * @throws IOException
27 | */
28 | protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
29 |
30 | if(!Authentication.isLogin(request)){
31 | return;
32 | }
33 | String usernamePara=request.getParameter("username");
34 |
35 | String sessionUsername=(String)request.getSession().getAttribute("username");
36 |
37 | if(usernamePara.equals(sessionUsername)){
38 | request.getSession().invalidate();
39 | System.out.println("用户"+usernamePara+"退出登录");
40 | }
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/API/GetFileList.java:
--------------------------------------------------------------------------------
1 | package api;
2 |
3 | import model.DbUtil;
4 | import org.json.JSONException;
5 | import org.json.JSONObject;
6 | import utils.Authentication;
7 |
8 | import javax.servlet.ServletException;
9 | import javax.servlet.annotation.WebServlet;
10 | import javax.servlet.http.HttpServlet;
11 | import javax.servlet.http.HttpServletRequest;
12 | import javax.servlet.http.HttpServletResponse;
13 | import java.io.IOException;
14 | import java.sql.*;
15 |
16 |
17 |
18 | /**
19 | * 网盘文件列表接口
20 | */
21 | @WebServlet(name = "GetFileList", urlPatterns = "/getFileList")
22 | public class GetFileList extends HttpServlet {
23 |
24 | /**
25 | * 获取 用户名 参数,返回该用户网盘中存储的文件信息
26 | *
27 | * @param request
28 | * @param response
29 | * @throws ServletException
30 | * @throws IOException
31 | */
32 | protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
33 | response.setContentType("text/html; charset=utf-8");
34 | if (!Authentication.isLogin(request)) {
35 | return;
36 | }
37 |
38 | try {
39 | //获取结果集
40 | ResultSet resultSet = DbUtil.selectToSet("select filename,filesize,time from " +
41 | request.getSession().getAttribute("username") + ";");
42 |
43 | //组装json对象
44 | JSONObject data = new JSONObject();
45 | while (resultSet.next()) {
46 | JSONObject file = new JSONObject();
47 | file.put("filename", resultSet.getString("filename"));
48 | file.put("filesize", resultSet.getString("filesize"));
49 | file.put("time", resultSet.getTimestamp("time"));
50 | data.append("files", file);
51 | }
52 |
53 | //返回数据
54 | response.getWriter().print(data);
55 |
56 | } catch (SQLException | JSONException e) {
57 | e.printStackTrace();
58 | }
59 |
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/src/API/GetUsername.java:
--------------------------------------------------------------------------------
1 | package api;
2 |
3 | import javax.servlet.ServletException;
4 | import javax.servlet.annotation.WebServlet;
5 | import javax.servlet.http.HttpServlet;
6 | import javax.servlet.http.HttpServletRequest;
7 | import javax.servlet.http.HttpServletResponse;
8 | import java.io.IOException;
9 |
10 | @WebServlet(name = "getUsername",urlPatterns = "/getUsername")
11 | public class GetUsername extends HttpServlet {
12 |
13 | protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
14 | response.setContentType("text/html;charset=utf-8");
15 | response.getWriter().print(request.getSession().getAttribute("username"));
16 |
17 | //Jedis jedis =new Jedis();
18 | //jedis.set("xx","yyy");
19 | //jedis.zrangebyscore
20 |
21 |
22 | }
23 | }
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/src/Model/DBUtil.java:
--------------------------------------------------------------------------------
1 | package model;
2 |
3 | import java.sql.*;
4 |
5 | /**
6 | * 数据库工具类
7 | *
8 | * 用来获取数据库连接
9 | */
10 |
11 |
12 | public class DbUtil {
13 | public static Connection connection = null;
14 |
15 | static String dbName = "netdisc";
16 |
17 | static {
18 | try {
19 | //加载驱动
20 | Class.forName("com.mysql.cj.jdbc.Driver");
21 | } catch (ClassNotFoundException e) {
22 | e.printStackTrace();
23 | }
24 | }
25 |
26 | /**
27 | * 用 数据库名 做参数调用该方法,返回一个创建好的数据库连接
28 | *
29 | * @param db
30 | * @return Connection
31 | */
32 | public static Connection getConnection(String db) {
33 | try {
34 | //获得数据库链接
35 | connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/" + db + "?serverTimezone=Asia/Shanghai", "root", "");
36 | } catch (SQLException e) {
37 | e.printStackTrace();
38 | }
39 | return connection;
40 | }
41 |
42 | /**
43 | * 执行查询语句,选择某些列 返回该列的值 (int 类型)
44 | *
45 | * @param SQL
46 | * @param colName
47 | * @return
48 | */
49 | public static int selectToInt(String SQL, String colName) {
50 | Connection connection = getConnection(dbName);
51 | int data = 0;
52 | try {
53 | Statement statement = connection.createStatement();
54 | ResultSet resultSet = statement.executeQuery(SQL);
55 |
56 | while (resultSet.next()) {
57 | data = resultSet.getInt(colName);
58 | }
59 | connection.close();
60 | statement.close();
61 | resultSet.close();
62 | } catch (SQLException e) {
63 | e.printStackTrace();
64 | } finally {
65 | return data;
66 | }
67 | }
68 |
69 | /**
70 | * 执行查询语句,选择某些列 返回该列的值 (String 类型)
71 | *
72 | * @param SQL
73 | * @param colName
74 | * @return
75 | */
76 | public static String selectToString(String SQL, String colName) {
77 | Connection connection = getConnection(dbName);
78 | try {
79 | Statement statement = connection.createStatement();
80 | } catch (SQLException e) {
81 | e.printStackTrace();
82 | }
83 | return "";
84 | }
85 |
86 | public static ResultSet selectToSet(String SQL) {
87 | Connection connection = getConnection(dbName);
88 | ResultSet resultSet=null;
89 | try {
90 | Statement statement = connection.createStatement();
91 | resultSet = statement.executeQuery(SQL);
92 |
93 | } catch (SQLException e) {
94 | e.printStackTrace();
95 | } finally {
96 | return resultSet;
97 | }
98 | }
99 |
100 | public static boolean execute(String SQL) {
101 | Connection connection = getConnection(dbName);
102 | boolean successful = false;
103 | try {
104 | Statement statement = connection.createStatement();
105 | successful = statement.execute(SQL);
106 | connection.close();
107 | statement.close();
108 | } catch (SQLException e) {
109 | e.printStackTrace();
110 | } finally {
111 | return successful;
112 |
113 | }
114 | }
115 | }
116 |
--------------------------------------------------------------------------------
/src/Model/FileDownload.java:
--------------------------------------------------------------------------------
1 | package model;
2 |
3 | import utils.Authentication;
4 |
5 | import javax.servlet.ServletException;
6 | import javax.servlet.annotation.WebServlet;
7 | import javax.servlet.http.Cookie;
8 | import javax.servlet.http.HttpServlet;
9 | import javax.servlet.http.HttpServletRequest;
10 | import javax.servlet.http.HttpServletResponse;
11 | import java.io.*;
12 | import java.net.URLEncoder;
13 | import java.sql.Connection;
14 | import java.sql.ResultSet;
15 | import java.sql.SQLException;
16 | import java.sql.Statement;
17 |
18 | @WebServlet(name = "FileDownload", urlPatterns = "/downloadFile")
19 | public class FileDownload extends HttpServlet {
20 | protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
21 |
22 |
23 | if(!Authentication.isLogin(request)){
24 | return;
25 | }
26 |
27 | //获取文件名
28 | String filename = request.getParameter("filename");
29 |
30 | if (filename == null) {
31 | System.out.println("无 filename 参数");
32 | return;
33 | }
34 |
35 | System.out.println("filename = " + filename);
36 |
37 |
38 | //查找该用户的数据库,在数据库中找到文件对应的下载地址
39 |
40 | Connection connection=DbUtil.getConnection("netdisc");
41 |
42 | try {
43 | Statement statement=connection.createStatement();
44 |
45 | ResultSet resultSet=statement.executeQuery(
46 | "select filename,path from "+request.getSession().getAttribute("username")+
47 | " where filename='"+filename+"';");
48 |
49 | String path=null;
50 | while (resultSet.next()){
51 | path=resultSet.getString("path");
52 | }
53 |
54 | File file=new File(path);
55 |
56 | if (file.exists()) {
57 | // 配置响应头,指定响应类型为附件,对中文文件名进行编码
58 | response.addHeader("Content-Disposition",
59 | "attachment;filename=" + URLEncoder.encode(filename, "utf-8"));
60 |
61 | //添加文件大小信息
62 | response.addHeader("Content-Length", "" + file.length());
63 |
64 | InputStream inputStream = new FileInputStream(file);
65 |
66 | byte[] chars = new byte[1024];
67 | int len = -1;
68 | OutputStream out = response.getOutputStream();
69 | while ((len = inputStream.read(chars)) != -1) {
70 | out.write(chars, 0, len);
71 | }
72 | inputStream.close();
73 | }
74 |
75 | } catch (SQLException e) {
76 | e.printStackTrace();
77 | }
78 |
79 | }
80 |
81 | }
82 |
83 |
84 |
85 |
--------------------------------------------------------------------------------
/src/Model/FileUpload.java:
--------------------------------------------------------------------------------
1 | package model;
2 |
3 | import utils.Authentication;
4 |
5 | import javax.servlet.ServletException;
6 | import javax.servlet.annotation.MultipartConfig;
7 | import javax.servlet.annotation.WebServlet;
8 | import javax.servlet.http.*;
9 | import java.io.IOException;
10 | import java.sql.Connection;
11 | import java.sql.SQLException;
12 | import java.sql.Statement;
13 |
14 | @MultipartConfig
15 | @WebServlet(name = "FileUpload",urlPatterns = "/upload")
16 | public class FileUpload extends HttpServlet {
17 | @Override
18 | protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
19 |
20 | if(!Authentication.isLogin(request)){
21 | return;
22 | }
23 |
24 |
25 | //获取文件对象
26 | Part part=request.getPart("file");
27 |
28 | String filename=part.getSubmittedFileName();
29 |
30 | String path="D://0testFile/"+filename;
31 |
32 | //保存
33 | part.write(path);
34 |
35 | //----------------------------------- 更新数据库信息 ---------------------
36 |
37 | //获取数据库连接
38 | Connection connection=DbUtil.getConnection("netdisc");
39 |
40 | try {
41 | Statement statement=connection.createStatement();
42 | statement.execute("insert into "+request.getSession().getAttribute("username")+" values(0,'"+filename+"',"+part.getSize()+",now(),'"+path+"');");
43 |
44 | } catch (SQLException e) {
45 | e.printStackTrace();
46 | response.getWriter().print(e.getMessage());
47 | return;
48 | }
49 | response.sendRedirect("disc.html");
50 | }
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/src/Utils/Authentication.java:
--------------------------------------------------------------------------------
1 | package utils;
2 |
3 | import javax.servlet.http.HttpServletRequest;
4 | import javax.servlet.http.HttpSession;
5 |
6 |
7 | /**
8 | * 鉴权模块,验证用户是否有操作权限
9 | */
10 | public class Authentication {
11 |
12 | /**
13 | * 传入请求对象做参数,从请求所属的会话中,获取用户名属性
14 | * @param request
15 | * @return
16 | */
17 | public static boolean isLogin(HttpServletRequest request){
18 | String username=(String)request.getSession().getAttribute("username");
19 |
20 | //判断用户是否存在
21 | return username != null;
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/Utils/Encoder.java:
--------------------------------------------------------------------------------
1 | package utils;
2 |
3 | import java.security.MessageDigest;
4 | import java.security.NoSuchAlgorithmException;
5 | import java.util.Base64;
6 |
7 | public class Encoder {
8 |
9 |
10 | public static String encodeBase64(String data) {
11 | MessageDigest md= null;
12 | try {
13 | md = MessageDigest.getInstance("md5");
14 | } catch (NoSuchAlgorithmException e) {
15 | e.printStackTrace();
16 | }
17 | byte[] dataEncode= md.digest(data.getBytes());
18 |
19 | return Base64.getEncoder().encodeToString(dataEncode);
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/src/filters/EncodeFilter.java:
--------------------------------------------------------------------------------
1 | package filters;
2 |
3 | import javax.servlet.*;
4 | import javax.servlet.Filter;
5 | import javax.servlet.annotation.WebFilter;
6 | import javax.servlet.http.HttpServletRequest;
7 | import javax.servlet.http.HttpServletResponse;
8 | import java.io.IOException;
9 |
10 | /**
11 | * 编码过滤器,匹配所有请求
12 | */
13 | @WebFilter(filterName = "Filter1",urlPatterns = "/*")
14 | public class EncodeFilter implements Filter {
15 | public void destroy() {
16 | }
17 |
18 | /**
19 | * 将 请求编码 修改为utf-8编码
20 | *
21 | * @param req
22 | * @param resp
23 | * @param chain
24 | * @throws ServletException
25 | * @throws IOException
26 | */
27 | public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException, IOException {
28 | HttpServletRequest request=(HttpServletRequest) req;
29 | HttpServletResponse response=(HttpServletResponse)resp;
30 | System.out.println("编码过滤");
31 | request.setCharacterEncoding("utf-8");
32 |
33 | chain.doFilter(request, response);
34 | }
35 |
36 | public void init(FilterConfig config) throws ServletException {
37 |
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/src/filters/Filter.java:
--------------------------------------------------------------------------------
1 | package filters;
2 |
3 | import javax.servlet.*;
4 | import javax.servlet.annotation.WebFilter;
5 | import javax.servlet.http.HttpServletRequest;
6 | import javax.servlet.http.HttpServletResponse;
7 | import java.io.IOException;
8 |
9 | /**
10 | * 首页访问过滤
11 | */
12 | @WebFilter(filterName = "Filter2",urlPatterns = "/")
13 | public class Filter implements javax.servlet.Filter {
14 | //销毁
15 | public void destroy() {
16 | }
17 |
18 | /**
19 | * 从会话中获取 用户名 参数,跳转到对应用户的网盘页面
20 | * 若不存在,则跳转到登录页面
21 | * @param req
22 | * @param resp
23 | * @param chain
24 | * @throws ServletException
25 | * @throws IOException
26 | */
27 | public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException, IOException {
28 | HttpServletRequest request=(HttpServletRequest) req;
29 | HttpServletResponse response=(HttpServletResponse)resp;
30 |
31 | String username=(String)request.getSession().getAttribute("username");
32 |
33 | System.out.println("首页跳转过滤");
34 | if(username==null){
35 | response.sendRedirect("user/login.html");
36 | }else {
37 | response.sendRedirect("disc.html");
38 | }
39 | }
40 |
41 | //初始化
42 | public void init(FilterConfig config) throws ServletException {
43 |
44 | }
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/src/user/LoginController.java:
--------------------------------------------------------------------------------
1 | package user;
2 |
3 | import model.DbUtil;
4 | import utils.Encoder;
5 |
6 | import javax.servlet.ServletException;
7 | import javax.servlet.annotation.WebServlet;
8 | import javax.servlet.http.HttpServlet;
9 | import javax.servlet.http.HttpServletRequest;
10 | import javax.servlet.http.HttpServletResponse;
11 | import java.io.IOException;
12 | import java.sql.Connection;
13 | import java.sql.ResultSet;
14 | import java.sql.SQLException;
15 | import java.sql.Statement;
16 |
17 | @WebServlet(name = "LoginController", urlPatterns = "/user/userLogin")
18 | public class LoginController extends HttpServlet {
19 |
20 | protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
21 | String username = request.getParameter("username");
22 | String password = request.getParameter("password");
23 | System.out.println("username = " + username);
24 | System.out.println("password = " + password);
25 |
26 | //密码加密
27 | password = Encoder.encodeBase64(password);
28 |
29 | int userCount = DbUtil.selectToInt("select count(username) from user where username=\""
30 | + username + "\" and password=\"" + password + "\";", "count(username)");
31 | if (userCount == 0) {
32 | System.out.println("用户名或密码错误");
33 | return;
34 | }
35 |
36 | //保存登录状态
37 | request.getSession().setAttribute("username", username);
38 | response.sendRedirect("../disc.html");
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/user/RegisterController.java:
--------------------------------------------------------------------------------
1 | package user;
2 |
3 | import model.DbUtil;
4 | import utils.Encoder;
5 |
6 | import javax.servlet.ServletException;
7 | import javax.servlet.annotation.WebServlet;
8 | import javax.servlet.http.HttpServlet;
9 | import javax.servlet.http.HttpServletRequest;
10 | import javax.servlet.http.HttpServletResponse;
11 | import java.io.IOException;
12 | import java.sql.Connection;
13 | import java.sql.ResultSet;
14 | import java.sql.SQLException;
15 | import java.sql.Statement;
16 |
17 | @WebServlet(name = "RegisterController", urlPatterns = "/user/userRegister")
18 | public class RegisterController extends HttpServlet {
19 | @Override
20 | protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
21 | String username = request.getParameter("username");
22 | String password = request.getParameter("password");
23 |
24 | //前端验证:密码跟用户名都有时,才能发送请求
25 |
26 |
27 | //查找是否有重复用户,有则报错
28 | int userCount = DbUtil.selectToInt("select count(username) from user where username=\""
29 | + username + "\";", "count(username)");
30 |
31 | if (userCount > 0) {
32 | System.out.println("用户已存在");
33 | return;
34 | }
35 |
36 | //加密密码
37 | password = Encoder.encodeBase64(password);
38 |
39 | //将注册用户的信息插入数据库
40 | DbUtil.execute("insert into user values(0,\"" + username + "\",\"" + password + "\");");
41 |
42 | //用户创建成功后,为其创建文件表
43 | DbUtil.execute("create table " + username + "(id int auto_increment not null,filename varchar(50) not null," +
44 | "filesize bigint not null,time timestamp default current_timestamp,path varchar(100) not null,primary key(id));");
45 |
46 | //filesize long bigint
47 |
48 | System.out.println("ok");
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/web/WEB-INF/web.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
--------------------------------------------------------------------------------
/web/disc.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | 在线网盘
7 |
8 |
9 |
51 |
52 |
53 |
62 |
63 |
64 |
65 |
66 |
67 |
85 |
86 |
87 |
--------------------------------------------------------------------------------
/web/getUser.js:
--------------------------------------------------------------------------------
1 | let ajax=new XMLHttpRequest();
2 | ajax.onreadystatechange=function(){
3 | if(ajax.readyState==4 && ajax.status==200){
4 | //做什么
5 | document.getElementById("username").innerText=ajax.responseText;
6 | // document.cookie="username="+ajax.responseText;
7 |
8 | //拉取文件列表
9 | let ajaxfl=new XMLHttpRequest();
10 | ajaxfl.onreadystatechange=function(){
11 | if(ajaxfl.readyState==4 && ajaxfl.status==200){
12 | //做什么
13 | let data=JSON.parse(ajaxfl.responseText);
14 | let len=data.files.length;
15 | let table=document.getElementById("fileList");
16 | for(let i=0;i
2 |
3 |
4 |
5 | about
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/web/info/money.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | money
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/web/info/techSupport.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | techSupport
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/web/style.css:
--------------------------------------------------------------------------------
1 | .menu {
2 | display: flex;
3 | width: 100%;
4 | background: #1e272e;
5 | }
6 |
7 | .logo {
8 | flex: auto;
9 | font-size: 30px;
10 | padding: 10px 50px;
11 | color: white;
12 | }
13 |
14 | .menuItems {
15 | flex: auto;
16 | justify-content: flex-end;
17 | display: flex;
18 | }
19 |
20 | .menuItem:hover {
21 | background: #ff3f34;
22 | cursor: pointer;
23 | }
24 |
25 | .menuItem {
26 | font-size: 20px;
27 | font-weight: lighter;
28 | text-decoration: none;
29 | color: white;
30 | padding: 20px 50px;
31 | }
32 |
33 | body {
34 | background-image: url("https://pan.baidu.com/static/images/16new/bg3.jpg");
35 | background-size: cover;
36 | background-position-y: 65px;
37 | margin: 0;
38 | font-family: "Microsoft YaHei UI";
39 | }
40 |
41 | .card {
42 | position: absolute;
43 | top: 50%;
44 | left: 70%;
45 | transform: translate(-50%, -50%);
46 | background: white;
47 | border-radius: 10px;
48 | box-shadow: #111111 1px 1px 10px;
49 | overflow: hidden;
50 | }
51 |
52 | .content:before {
53 | content: "“";
54 | color: #d2dae2;
55 | font-size: 70px;
56 | font-weight: bold;
57 | }
58 |
59 | .content {
60 | color: white;
61 | position: absolute;
62 | top: 50%;
63 | left: 15%;
64 | font-size: 50px;
65 |
66 | }
67 |
68 | .content:after {
69 | content: "”";
70 | color: #d2dae2;
71 | font-size: 70px;
72 | font-weight: bold;
73 | }
74 |
75 | form {
76 | margin: 30px 30px 0;
77 | }
78 |
79 | .title {
80 | justify-content: center;
81 | font-size: 25px;
82 | font-weight: bold;
83 | display: flex;
84 | margin: 0 auto 25px;
85 | }
86 |
87 | input[type="text"], input[type="password"] {
88 | display: block;
89 | font-size: 15px;
90 | width: 300px;
91 | padding: 14px 10px;
92 | outline: none;
93 | border: solid 1px #d2dae2;
94 | text-align: left;
95 | margin: 5px 0;
96 | }
97 |
98 | .remember {
99 | display: block;
100 | font-size: 13px;
101 | margin: 15px 0;
102 | }
103 |
104 | input[type="submit"] {
105 | display: block;
106 | padding: 12px 140px;
107 | border-radius: 5px;
108 | font-size: 15px;
109 | outline: none;
110 | border: none;
111 | cursor: pointer;
112 | background: #0fbcf9;
113 | color: white;
114 | margin: auto;
115 | }
116 |
117 | .function {
118 | margin: 20px 0 0;
119 | background: rgba(213, 233, 250, 0.58);
120 | padding: 20px;
121 | }
122 |
123 | .funcItem {
124 | font-size: 17px;
125 | font-weight: lighter;
126 | text-decoration: none;
127 | padding: 40px;
128 | color: #0fbcf9;
129 | }
--------------------------------------------------------------------------------
/web/user/login.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | 在线网盘
7 |
8 |
9 |
10 |
20 | 多端并用
数据随身携带
21 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/web/user/register.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | 用户注册
6 |
7 |
8 |
9 |
19 | 多端并用
数据随身携带
20 |
21 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------