├── .gitignore ├── WebContent ├── META-INF │ └── MANIFEST.MF ├── images │ ├── 02.png │ ├── 1024.png │ ├── admin.jpg │ ├── logo1.png │ ├── user.jpg │ ├── users.jpg │ └── userhead.png ├── WEB-INF │ ├── lib │ │ ├── c3p0-0.9.5.5.jar │ │ ├── mchange-commons-java-0.2.19.jar │ │ ├── mysql-connector-java-8.0.22.jar │ │ └── c3p0-oracle-thin-extras-0.9.5.5.jar │ └── web.xml └── css │ ├── layout.css │ ├── style.css │ ├── style1.css │ └── reset.css ├── assets ├── 2021-11-03-17-20-36.png ├── 2021-11-04-18-31-14.png ├── 2021-11-04-19-04-12.png ├── 2021-11-04-19-07-38.png ├── 2021-11-04-19-13-22.png └── 2021-11-04-19-15-32.png ├── src ├── dbconfig.properties ├── model │ └── Users.java ├── startup │ └── FirstServlet.java ├── exception │ └── IdIsNullException.java ├── util │ ├── C3P0Util.java │ ├── DBHelper.java │ ├── JdbcUtil.java │ ├── FileUtil.java │ ├── DownloadFile.java │ └── OperUtil.java ├── wrapper │ └── MyHttpServletRequest.java ├── c3p0-config.xml ├── filter │ └── CharacterEncodingFilter.java ├── controller │ ├── FindUser.java │ ├── RegisterController.java │ ├── LoginController.java │ ├── FindFileAdmin.java │ ├── AdminHome.java │ ├── MyShare.java │ ├── FindFile.java │ ├── PublicShare.java │ ├── Upload.java │ ├── PublicManager.java │ ├── UserFile.java │ └── Home.java ├── service │ ├── impl │ │ └── UserServiceImpl.java │ └── UserService.java ├── dao │ └── UserDao.java └── view │ ├── Register.java │ ├── Login.java │ ├── FindUserView.java │ ├── AdminMain.java │ ├── FindFileAdminView.java │ ├── MyShareView.java │ ├── FindAnyView.java │ ├── PublicShareView.java │ ├── PublicManagerView.java │ ├── Main.java │ └── UserFileView.java ├── README.md ├── pan.iml ├── pan_db.sql └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | # Project exclude paths 2 | /out/ -------------------------------------------------------------------------------- /WebContent/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Class-Path: 3 | 4 | -------------------------------------------------------------------------------- /WebContent/images/02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/b1ackc4t/pan/HEAD/WebContent/images/02.png -------------------------------------------------------------------------------- /WebContent/images/1024.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/b1ackc4t/pan/HEAD/WebContent/images/1024.png -------------------------------------------------------------------------------- /WebContent/images/admin.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/b1ackc4t/pan/HEAD/WebContent/images/admin.jpg -------------------------------------------------------------------------------- /WebContent/images/logo1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/b1ackc4t/pan/HEAD/WebContent/images/logo1.png -------------------------------------------------------------------------------- /WebContent/images/user.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/b1ackc4t/pan/HEAD/WebContent/images/user.jpg -------------------------------------------------------------------------------- /WebContent/images/users.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/b1ackc4t/pan/HEAD/WebContent/images/users.jpg -------------------------------------------------------------------------------- /WebContent/images/userhead.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/b1ackc4t/pan/HEAD/WebContent/images/userhead.png -------------------------------------------------------------------------------- /assets/2021-11-03-17-20-36.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/b1ackc4t/pan/HEAD/assets/2021-11-03-17-20-36.png -------------------------------------------------------------------------------- /assets/2021-11-04-18-31-14.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/b1ackc4t/pan/HEAD/assets/2021-11-04-18-31-14.png -------------------------------------------------------------------------------- /assets/2021-11-04-19-04-12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/b1ackc4t/pan/HEAD/assets/2021-11-04-19-04-12.png -------------------------------------------------------------------------------- /assets/2021-11-04-19-07-38.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/b1ackc4t/pan/HEAD/assets/2021-11-04-19-07-38.png -------------------------------------------------------------------------------- /assets/2021-11-04-19-13-22.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/b1ackc4t/pan/HEAD/assets/2021-11-04-19-13-22.png -------------------------------------------------------------------------------- /assets/2021-11-04-19-15-32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/b1ackc4t/pan/HEAD/assets/2021-11-04-19-15-32.png -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/c3p0-0.9.5.5.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/b1ackc4t/pan/HEAD/WebContent/WEB-INF/lib/c3p0-0.9.5.5.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/mchange-commons-java-0.2.19.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/b1ackc4t/pan/HEAD/WebContent/WEB-INF/lib/mchange-commons-java-0.2.19.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/mysql-connector-java-8.0.22.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/b1ackc4t/pan/HEAD/WebContent/WEB-INF/lib/mysql-connector-java-8.0.22.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/c3p0-oracle-thin-extras-0.9.5.5.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/b1ackc4t/pan/HEAD/WebContent/WEB-INF/lib/c3p0-oracle-thin-extras-0.9.5.5.jar -------------------------------------------------------------------------------- /src/dbconfig.properties: -------------------------------------------------------------------------------- 1 | mysql.driverClassName=com.mysql.cj.jdbc.Driver 2 | mysql.url=jdbc:mysql://127.0.0.1:3306/pan_db?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8&useSSL=false 3 | mysql.user=root 4 | mysql.pwd= -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 基本介绍 2 | 3 | java结课设计,一款完全基于servlet的网盘系统,无后端框架、无jsp。 4 | 5 | 提供一个存储自己资源、分享自己资源、享受他人资源的文件共享平台。 6 | 7 | # 快速搭建 8 | 9 | ```bash 10 | git clone 11 | cd ./pan 12 | ``` 13 | 14 | 使用项目里的.sql文件创建好项目所需的数据库 15 | 16 | ![](./assets/2021-11-03-17-20-36.png) 17 | 18 | 修改项目里两个的数据库配置文件为自己可用的数据库 19 | 20 | 编译成war包部署/直接将Webcontent部署到tomcat的webapp目录 21 | 22 | Tips:第一次启动需要注册一个用户名为admin的账号,默认为管理员权限 23 | 24 | # 项目展示 25 | 26 | ![](./assets/2021-11-04-18-31-14.png) 27 | 28 | ![](./assets/2021-11-04-19-07-38.png) 29 | 30 | ![](./assets/2021-11-04-19-15-32.png) 31 | 32 | ![](./assets/2021-11-04-19-04-12.png) 33 | -------------------------------------------------------------------------------- /src/model/Users.java: -------------------------------------------------------------------------------- 1 | package model; 2 | 3 | import java.io.Serializable; 4 | import java.util.Date; 5 | 6 | public class Users implements Serializable{ 7 | 8 | private Integer id; 9 | private String name; 10 | private String pwd; 11 | 12 | public Integer getId() { 13 | return id; 14 | } 15 | public void setId(Integer id) { 16 | this.id = id; 17 | } 18 | public String getName() { 19 | return name; 20 | } 21 | public void setName(String name) { 22 | this.name = name; 23 | } 24 | public String getPwd() { 25 | return pwd; 26 | } 27 | public void setPwd(String pwd) { 28 | this.pwd = pwd; 29 | } 30 | 31 | 32 | @Override 33 | public String toString() { 34 | return "Users [id=" + id + ", name=" + name + ", pwd=" + pwd + "]"; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/startup/FirstServlet.java: -------------------------------------------------------------------------------- 1 | package startup; 2 | 3 | import javax.servlet.GenericServlet; 4 | import javax.servlet.ServletException; 5 | import javax.servlet.ServletRequest; 6 | import javax.servlet.ServletResponse; 7 | import java.io.File; 8 | import java.io.IOException; 9 | 10 | public class FirstServlet extends GenericServlet { 11 | 12 | @Override 13 | public void init() throws ServletException { 14 | 15 | File f1 = new File("./userfile"); 16 | File f2 = new File("./publicshare"); 17 | if (!f1.exists()) { 18 | f1.mkdir(); 19 | } 20 | if (!f2.exists()) { 21 | f2.mkdir(); 22 | } 23 | } 24 | 25 | @Override 26 | public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException { 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/exception/IdIsNullException.java: -------------------------------------------------------------------------------- 1 | package exception; 2 | 3 | public class IdIsNullException extends Exception { 4 | 5 | public IdIsNullException() { 6 | // TODO Auto-generated constructor stub 7 | } 8 | 9 | public IdIsNullException(String message) { 10 | super(message); 11 | // TODO Auto-generated constructor stub 12 | } 13 | 14 | public IdIsNullException(Throwable cause) { 15 | super(cause); 16 | // TODO Auto-generated constructor stub 17 | } 18 | 19 | public IdIsNullException(String message, Throwable cause) { 20 | super(message, cause); 21 | // TODO Auto-generated constructor stub 22 | } 23 | 24 | public IdIsNullException(String message, Throwable cause, 25 | boolean enableSuppression, boolean writableStackTrace) { 26 | super(message, cause, enableSuppression, writableStackTrace); 27 | // TODO Auto-generated constructor stub 28 | } 29 | 30 | } 31 | 32 | -------------------------------------------------------------------------------- /src/util/C3P0Util.java: -------------------------------------------------------------------------------- 1 | package util; 2 | 3 | import java.sql.Connection; 4 | import java.sql.ResultSet; 5 | import java.sql.SQLException; 6 | import java.sql.Statement; 7 | 8 | import com.mchange.v2.c3p0.ComboPooledDataSource; 9 | 10 | public class C3P0Util { 11 | 12 | private static ComboPooledDataSource cpds = new ComboPooledDataSource("mysql"); 13 | 14 | 15 | 16 | public static Connection getConnection() throws SQLException{ 17 | return cpds.getConnection(); 18 | } 19 | 20 | public static void release(ResultSet rs,Statement ps,Connection conn) throws SQLException{ 21 | if (rs != null) { 22 | rs.close(); 23 | rs = null; // 垃圾回收,上! 24 | } 25 | if (ps != null) { 26 | ps.close(); 27 | ps = null; // 垃圾回收,上! 28 | } 29 | if (conn != null) { 30 | conn.close(); 31 | conn = null; // 垃圾回收,上! 32 | } 33 | } 34 | 35 | public static void main(String[] args) throws SQLException { 36 | 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/wrapper/MyHttpServletRequest.java: -------------------------------------------------------------------------------- 1 | package wrapper; 2 | 3 | import java.io.UnsupportedEncodingException; 4 | import javax.servlet.http.HttpServletRequest; 5 | import javax.servlet.http.HttpServletRequestWrapper; 6 | 7 | public class MyHttpServletRequest extends HttpServletRequestWrapper { 8 | 9 | HttpServletRequest request; 10 | 11 | public MyHttpServletRequest(HttpServletRequest request) { 12 | super(request); 13 | this.request = request; 14 | } 15 | 16 | public String getParameter(String name) { 17 | 18 | String value = request.getParameter(name); 19 | 20 | if (value == null) 21 | return null; 22 | 23 | // 只考虑get方式 24 | String method = request.getMethod(); 25 | 26 | if ("get".equalsIgnoreCase(method)) { 27 | try { 28 | value = new String(value.getBytes("iso-8859-1"), 29 | request.getCharacterEncoding()); 30 | } catch (UnsupportedEncodingException e) { 31 | e.printStackTrace(); 32 | } 33 | } 34 | 35 | return value; 36 | 37 | } 38 | 39 | } 40 | 41 | -------------------------------------------------------------------------------- /src/c3p0-config.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 5 | 30 6 | 100 7 | 10 8 | 200 9 | 10 | 11 | 12 | com.mysql.cj.jdbc.Driver 13 | jdbc:mysql://127.0.0.1:3306/pan_db?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8&useSSL=false 14 | root 15 | 16 | 10 17 | 30 18 | 100 19 | 10 20 | 200 21 | 22 | -------------------------------------------------------------------------------- /pan.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 | -------------------------------------------------------------------------------- /src/filter/CharacterEncodingFilter.java: -------------------------------------------------------------------------------- 1 | package filter; 2 | 3 | import java.io.IOException; 4 | 5 | import javax.servlet.Filter; 6 | import javax.servlet.FilterChain; 7 | import javax.servlet.FilterConfig; 8 | import javax.servlet.ServletException; 9 | import javax.servlet.ServletRequest; 10 | import javax.servlet.ServletResponse; 11 | import javax.servlet.http.HttpServletRequest; 12 | import javax.servlet.http.HttpServletResponse; 13 | 14 | import wrapper.MyHttpServletRequest; 15 | 16 | public class CharacterEncodingFilter implements Filter { 17 | 18 | private FilterConfig filterConfig; 19 | 20 | @Override 21 | public void destroy() { 22 | // TODO Auto-generated method stub 23 | 24 | } 25 | 26 | @Override 27 | public void doFilter(ServletRequest req, ServletResponse res, 28 | FilterChain chain) throws IOException, ServletException { 29 | 30 | HttpServletRequest request=(HttpServletRequest) req; 31 | HttpServletResponse response=(HttpServletResponse) res; 32 | 33 | String encode=filterConfig.getInitParameter("encode"); 34 | 35 | request.setCharacterEncoding(encode); 36 | response.setContentType("text/html;charset="+encode); 37 | 38 | MyHttpServletRequest mrequest=new MyHttpServletRequest(request); 39 | 40 | chain.doFilter(mrequest, response); 41 | 42 | } 43 | 44 | @Override 45 | public void init(FilterConfig filterConfig) throws ServletException { 46 | this.filterConfig=filterConfig; 47 | } 48 | 49 | } 50 | 51 | -------------------------------------------------------------------------------- /WebContent/css/layout.css: -------------------------------------------------------------------------------- 1 | @charset "utf-8"; 2 | body, input, textarea, select, button, code, pre {font-family:"Arial", "PingFangSC-Light", "Microsoft Yahei", "宋体", sans-serif;} 3 | body {font-size:12px; color:#222;} 4 | a {color:#222; text-decoration:none;} 5 | a:focus {outline:0; -moz-outline:none;} /*for ff*/ 6 | a:hover {text-decoration:none;} 7 | body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,code,pre,form,fieldset,legend,input,button,textarea,area,blockquote,th,td,p {margin:0; padding:0;} 8 | img, a img, button {border:0;} 9 | img {vertical-align:middle;} 10 | table {border-collapse:collapse; border-spacing:0;} 11 | ul li {list-style-type:none;} 12 | input, textarea, select, button {outline:none;} 13 | input[type="text"], textarea {resize:none; -webkit-appearance:none; border-radius:0;} 14 | button[type="submit"], button[type="button"], input[type="submit"], input[type="button"], label, label input[type="checkbox"], label input[type="radio"] {cursor:pointer;} 15 | select {border:1px #ddd solid;} 16 | /*重置select默认样式*/ 17 | select {appearance:none; -moz-appearance:none; -webkit-appearance:none; background:url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAGBAMAAAAFwGKyAAAAElBMVEUAAAAAAAAAAAAAAAAAAAAAAADgKxmiAAAABXRSTlMAvDS0P4Bi/F4AAAAjSURBVAjXYxANDWQAAtfQEBDFGCoAophCFRhAwJgBDJRABABR1wLcaCoA8QAAAABJRU5ErkJggg==") no-repeat right center #fff; height:24px; padding-right:5px; border-radius:0;} 18 | /** {touch-action:pan-y;}*/ 19 | 20 | body, html {width:100%; overflow-x:hidden;} -------------------------------------------------------------------------------- /src/controller/FindUser.java: -------------------------------------------------------------------------------- 1 | package controller; 2 | 3 | import java.io.IOException; 4 | 5 | import javax.servlet.ServletException; 6 | import javax.servlet.http.HttpServlet; 7 | import javax.servlet.http.HttpServletRequest; 8 | import javax.servlet.http.HttpServletResponse; 9 | import javax.servlet.http.HttpSession; 10 | 11 | import service.UserService; 12 | import service.impl.UserServiceImpl; 13 | import java.util.List; 14 | 15 | public class FindUser extends HttpServlet { 16 | 17 | UserService userService = new UserServiceImpl(); 18 | 19 | public void doGet(HttpServletRequest req, HttpServletResponse res) 20 | throws ServletException, IOException { 21 | 22 | req.setCharacterEncoding("utf-8"); 23 | res.setContentType("text/html;charset=utf-8"); 24 | HttpSession session = req.getSession(); 25 | List userli = null; 26 | String key = req.getParameter("key"); 27 | if(!session.isNew() && session.getAttribute("name") != null) { 28 | if(session.getAttribute("name").equals("admin")){ 29 | ; 30 | } else { 31 | res.sendRedirect("./Login"); 32 | return; 33 | } 34 | } else { 35 | res.sendRedirect("./Login"); 36 | return; 37 | } 38 | 39 | if (!key.equals("") && (userli=userService.findUser(key)) != null ) { 40 | req.setAttribute("userli", userli); 41 | } 42 | req.getRequestDispatcher("/FindUserView").forward(req, res); 43 | 44 | 45 | } 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | public void doPost(HttpServletRequest req, HttpServletResponse res) 54 | throws ServletException, IOException { 55 | 56 | this.doGet(req, res); 57 | 58 | } 59 | 60 | 61 | 62 | } 63 | -------------------------------------------------------------------------------- /src/util/DBHelper.java: -------------------------------------------------------------------------------- 1 | package util; 2 | 3 | import java.sql.Connection; 4 | import java.sql.PreparedStatement; 5 | import java.sql.ResultSet; 6 | import java.sql.SQLException; 7 | 8 | public class DBHelper { 9 | 10 | private static Connection conn = null; 11 | private static PreparedStatement ps = null; 12 | private static ResultSet rs = null; 13 | 14 | public static Connection getConn() { 15 | return conn; 16 | } 17 | 18 | public static PreparedStatement getPs() { 19 | return ps; 20 | } 21 | 22 | public static int executeUpdate(String sql, Object[] params) 23 | throws SQLException { 24 | 25 | int res = -1; 26 | 27 | // conn=JdbcUtil.getConnection(); 28 | conn = C3P0Util.getConnection(); 29 | ps = conn.prepareStatement(sql); 30 | 31 | if (params != null) { 32 | for (int i = 0; i < params.length; i++) { 33 | ps.setObject(i + 1, params[i]); 34 | } 35 | } 36 | 37 | res = ps.executeUpdate(); 38 | 39 | // JdbcUtil.release(null, ps, conn); 40 | C3P0Util.release(null, ps, conn); 41 | 42 | return res; 43 | 44 | } 45 | 46 | public static ResultSet executeQuery(String sql, Object[] params) 47 | throws SQLException { 48 | 49 | ResultSet rs = null; 50 | 51 | // conn=JdbcUtil.getConnection(); 52 | conn = C3P0Util.getConnection(); 53 | ps = conn.prepareStatement(sql); 54 | 55 | if (params != null) { 56 | for (int i = 0; i < params.length; i++) { 57 | ps.setObject(i + 1, params[i]); 58 | } 59 | } 60 | 61 | rs = ps.executeQuery(); 62 | 63 | // JdbcUtil.release(null, ps, conn); //延迟关闭 64 | // C3P0Util.release(null, ps, conn); //延迟关闭 65 | 66 | return rs; 67 | 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /WebContent/css/style.css: -------------------------------------------------------------------------------- 1 | *{margin:0;padding:0;font-size:13px;font-family:microsoft yahei} 2 | html,body{width:100%;height:100%;background:#fff} 3 | 4 | #container{width:100%;height:100%;position:fixed;top:0;left:0;z-index:999} 5 | #output{width:100%;height:100%} 6 | .prompt{width:60%;height:30px;margin:5px auto;text-align:center;line-height:30px;font-family:microsoft yahei,Arial,sans-serif;font-size:13px;color:#df0000} 7 | .containerT{width:400px;height:300px;text-align:center;position:absolute;top:50%;left:50%;margin:-150px 0 0 -200px;border-radius:3px} 8 | .containerT h1{font-size:18px;font-family:microsoft yahei,Arial,sans-serif;-webkit-transition-duration:1s;transition-duration:1s;-webkit-transition-timing-function:ease-in-put;transition-timing-function:ease-in-put;font-weight:500} 9 | form{padding:20px 0;position:relative;z-index:2} 10 | form input{-webkit-appearance:none;-moz-appearance:none;appearance:none;outline:0;border:1px solid rgba(255,255,255,.4);background-color:rgba(255,255,255,.2);width:200px;border-radius:3px;padding:8px 15px;margin:0 auto 10px;display:block;text-align:center;font-size:15px;color:#fff;-webkit-transition-duration:.25s;transition-duration:.25s;font-weight:300} 11 | form input:hover{background-color:rgba(255,255,255,.4)} 12 | form input:focus{background-color:#fff;width:230px;color:#333} 13 | form button{-webkit-appearance:none;-moz-appearance:none;appearance:none;outline:0;background-color:#fff;border:0;padding:10px 15px;color:#333;border-radius:3px;width:200px;cursor:pointer;font-family:microsoft yahei,Arial,sans-serif;font-size:16px;font-weight:700;-webkit-transition-duration:.25s;transition-duration:.25s} 14 | form button:hover{background-color:#f5f7f9} -------------------------------------------------------------------------------- /src/controller/RegisterController.java: -------------------------------------------------------------------------------- 1 | package controller; 2 | 3 | import java.io.IOException; 4 | import java.io.PrintWriter; 5 | 6 | import javax.servlet.ServletException; 7 | import javax.servlet.http.HttpServlet; 8 | import javax.servlet.http.HttpServletRequest; 9 | import javax.servlet.http.HttpServletResponse; 10 | 11 | 12 | import model.Users; 13 | import service.UserService; 14 | import service.impl.UserServiceImpl; 15 | import util.OperUtil; 16 | 17 | public class RegisterController extends HttpServlet { 18 | 19 | 20 | UserService userService = new UserServiceImpl(); 21 | 22 | public void doGet(HttpServletRequest req, HttpServletResponse res) 23 | throws ServletException, IOException { 24 | req.setCharacterEncoding("utf-8"); 25 | res.setContentType("text/html;charset=utf-8"); 26 | String name = req.getParameter("username"); 27 | String pwd = req.getParameter("password"); 28 | PrintWriter out = res.getWriter(); 29 | String sep = System.getProperty("file.separator"); 30 | String userpath = "." + sep + "userfile"; 31 | 32 | Users users = new Users(); 33 | users.setName(name);; 34 | users.setPwd(pwd); 35 | 36 | if (userService.addUser(users) > 0 && OperUtil.create(userpath, name+"qiandu")) { 37 | ; 38 | out.print(""); 40 | 41 | } else { 42 | out.print(""); 44 | } 45 | 46 | 47 | 48 | 49 | } 50 | 51 | public void doPost(HttpServletRequest req, HttpServletResponse res) 52 | throws ServletException, IOException { 53 | 54 | this.doGet(req, res); 55 | } 56 | 57 | } -------------------------------------------------------------------------------- /src/util/JdbcUtil.java: -------------------------------------------------------------------------------- 1 | package util; 2 | 3 | import java.io.IOException; 4 | import java.io.InputStream; 5 | import java.sql.Connection; 6 | import java.sql.DriverManager; 7 | import java.sql.ResultSet; 8 | import java.sql.SQLException; 9 | import java.util.Properties; 10 | 11 | import java.sql.Statement; 12 | /** 13 | * <:< 14 | * >:> 15 | *   16 | * &:& 17 | * @author Administrator 18 | * 19 | */ 20 | public class JdbcUtil { 21 | 22 | private static String driverClassName=null; 23 | private static String url=null; 24 | private static String user=null; 25 | private static String pwd=null; 26 | 27 | static{ 28 | InputStream is=JdbcUtil.class.getClassLoader().getResourceAsStream("dbconfig.properties"); 29 | Properties props=new Properties(); 30 | try { 31 | props.load(is); 32 | 33 | driverClassName=props.getProperty("mysql.driverClassName"); 34 | url=props.getProperty("mysql.url"); 35 | user=props.getProperty("mysql.user"); 36 | pwd=props.getProperty("mysql.pwd"); 37 | 38 | Class.forName(driverClassName); 39 | 40 | } catch (Exception e) { 41 | e.printStackTrace(); 42 | } 43 | } 44 | 45 | public static Connection getConnection() throws SQLException{ 46 | return DriverManager.getConnection(url, user, pwd); 47 | } 48 | 49 | public static void release(ResultSet rs,Statement ps,Connection conn) throws SQLException{ 50 | if (rs != null) { 51 | rs.close(); 52 | rs = null; // 垃圾回收,上! 53 | } 54 | if (ps != null) { 55 | ps.close(); 56 | ps = null; // 垃圾回收,上! 57 | } 58 | if (conn != null) { 59 | conn.close(); 60 | conn = null; // 垃圾回收,上! 61 | } 62 | } 63 | 64 | public static void main(String[] args) { 65 | 66 | 67 | 68 | 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /src/controller/LoginController.java: -------------------------------------------------------------------------------- 1 | package controller; 2 | 3 | import java.io.IOException; 4 | 5 | import javax.servlet.ServletException; 6 | import javax.servlet.http.Cookie; 7 | import javax.servlet.http.HttpServlet; 8 | import javax.servlet.http.HttpServletRequest; 9 | import javax.servlet.http.HttpServletResponse; 10 | import javax.servlet.http.HttpSession; 11 | 12 | import model.Users; 13 | import service.UserService; 14 | import service.impl.UserServiceImpl; 15 | 16 | public class LoginController extends HttpServlet { 17 | 18 | UserService userService = new UserServiceImpl(); 19 | 20 | public void doGet(HttpServletRequest req, HttpServletResponse res) 21 | throws ServletException, IOException { 22 | req.setCharacterEncoding("utf-8"); 23 | res.setContentType("text/html;charset=utf-8"); 24 | HttpSession session = req.getSession(); 25 | Cookie cookie = null; 26 | 27 | if(!session.isNew() && session.getAttribute("name") != null){ 28 | req.getRequestDispatcher("/Home").forward(req, res); 29 | } 30 | 31 | String name = req.getParameter("username"); 32 | String pwd = req.getParameter("pwd"); 33 | 34 | 35 | Users users = new Users(); 36 | users.setName(name); 37 | users.setPwd(pwd); 38 | 39 | if (users.getName() != null && userService.checkUser(users)) { 40 | 41 | String sessionId = session.getId(); 42 | cookie = new Cookie("JSESSIONID", sessionId); 43 | res.addCookie(cookie); 44 | session.setAttribute("name", name); 45 | req.getRequestDispatcher("/Home").forward(req, res); 46 | 47 | 48 | } else { 49 | 50 | String errMsg = "用户名不存在或密码错误!!!!!请重新输入!!!!!"; 51 | req.setAttribute("errMsg", errMsg); 52 | req.getRequestDispatcher("/Login").forward(req, res); 53 | } 54 | 55 | 56 | } 57 | 58 | public void doPost(HttpServletRequest req, HttpServletResponse res) 59 | throws ServletException, IOException { 60 | 61 | this.doGet(req, res); 62 | 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/controller/FindFileAdmin.java: -------------------------------------------------------------------------------- 1 | package controller; 2 | 3 | import java.io.IOException; 4 | 5 | import javax.servlet.ServletException; 6 | import javax.servlet.http.HttpServlet; 7 | import javax.servlet.http.HttpServletRequest; 8 | import javax.servlet.http.HttpServletResponse; 9 | import javax.servlet.http.HttpSession; 10 | import service.UserService; 11 | import service.impl.UserServiceImpl; 12 | import java.util.ArrayList; 13 | import java.util.List; 14 | 15 | 16 | public class FindFileAdmin extends HttpServlet { 17 | 18 | UserService userService = new UserServiceImpl(); 19 | 20 | public void doGet(HttpServletRequest req, HttpServletResponse res) 21 | throws ServletException, IOException { 22 | 23 | req.setCharacterEncoding("utf-8"); 24 | res.setContentType("text/html;charset=utf-8"); 25 | HttpSession session = req.getSession(); 26 | if(!session.isNew() && session.getAttribute("name") != null) { 27 | if(session.getAttribute("name").equals("admin")){ 28 | ; 29 | } else { 30 | res.sendRedirect("./Login"); 31 | return; 32 | } 33 | } else { 34 | res.sendRedirect("./Login"); 35 | return; 36 | } 37 | 38 | String key = (req.getParameter("key")!=null)?req.getParameter("key"):""; 39 | List filetotal = new ArrayList(); 40 | String name = null; 41 | 42 | if(!session.isNew() && session.getAttribute("name") != null){ 43 | name = (String)session.getAttribute("name"); 44 | } else { 45 | res.sendRedirect("./Login"); 46 | return; 47 | } 48 | 49 | if (!key.equals("") && (filetotal=userService.FindPublicShare(key)) != null ) { 50 | req.setAttribute("filetotal", filetotal); 51 | } 52 | req.getRequestDispatcher("/FindFileAdminView").forward(req, res); 53 | 54 | 55 | 56 | } 57 | 58 | 59 | 60 | 61 | public void doPost(HttpServletRequest req, HttpServletResponse res) 62 | throws ServletException, IOException { 63 | 64 | this.doGet(req, res); 65 | 66 | } 67 | 68 | 69 | 70 | } 71 | -------------------------------------------------------------------------------- /src/util/FileUtil.java: -------------------------------------------------------------------------------- 1 | package util; 2 | 3 | import java.io.File; 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | 7 | public class FileUtil { 8 | 9 | public static List getFiles(String path) { 10 | List files = new ArrayList(); 11 | File file = new File(path); 12 | File[] tempList = file.listFiles(); 13 | 14 | for (int i = 0; i < tempList.length; i++) { 15 | if (tempList[i].isFile()) { 16 | files.add(tempList[i].toString()); 17 | //文件名,不包含路径 18 | //String fileName = tempList[i].getName(); 19 | } 20 | } 21 | return files; 22 | } 23 | 24 | public static List getDirs(String path) { 25 | List dirs = new ArrayList(); 26 | File file = new File(path); 27 | File[] tempList = file.listFiles(); 28 | 29 | for (int i = 0; i < tempList.length; i++) { 30 | 31 | if (tempList[i].isDirectory()) { 32 | //这里就不递归了, 33 | dirs.add(tempList[i].toString()); 34 | } 35 | } 36 | return dirs; 37 | } 38 | 39 | 40 | public static String ext(String filename) { 41 | int index = filename.lastIndexOf("."); 42 | 43 | if (index == -1) { 44 | return null; 45 | } 46 | String result = filename.substring(index + 1); 47 | return result; 48 | } 49 | 50 | 51 | public static long getTotalSizeOfFilesInDir(File file) { 52 | if (file.isFile()) 53 | return file.length(); 54 | final File[] children = file.listFiles(); 55 | long total = 0; 56 | if (children != null) 57 | for (final File child : children) 58 | total += getTotalSizeOfFilesInDir(child); 59 | return total; 60 | 61 | } 62 | 63 | public static String addslashes(String temp) { 64 | return temp.replace("\\", "\\\\"); 65 | } 66 | 67 | public static void main(String[] args) { 68 | 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/util/DownloadFile.java: -------------------------------------------------------------------------------- 1 | package util; 2 | 3 | import java.io.File; 4 | import java.io.FileInputStream; 5 | import java.io.IOException; 6 | import java.io.PrintWriter; 7 | import java.net.URLEncoder; 8 | 9 | import javax.servlet.ServletException; 10 | import javax.servlet.http.HttpServlet; 11 | import javax.servlet.http.HttpServletRequest; 12 | import javax.servlet.http.HttpServletResponse; 13 | import javax.servlet.http.HttpSession; 14 | import javax.servlet.ServletOutputStream; 15 | 16 | import exception.IdIsNullException; 17 | import model.Users; 18 | import service.UserService; 19 | import service.impl.UserServiceImpl; 20 | 21 | public class DownloadFile extends HttpServlet { 22 | 23 | 24 | public void doGet(HttpServletRequest req, HttpServletResponse res) 25 | throws ServletException, IOException { 26 | 27 | req.setCharacterEncoding("utf-8"); 28 | res.setContentType("text/html;charset=utf-8"); 29 | String name = null; 30 | String path = null; 31 | HttpSession session = req.getSession(); 32 | if(!session.isNew() && session.getAttribute("name") != null){ 33 | name = (String)session.getAttribute("name"); 34 | } else { 35 | res.sendRedirect("./Login"); 36 | return; 37 | } 38 | String sep = System.getProperty("file.separator"); 39 | String file = req.getParameter("name"); //客户端传递的需要下载的文件名 40 | 41 | if (req.getParameter("target").equals("public")) { 42 | path = "." + sep + "publicshare" + req.getParameter("dir") + file; 43 | } else { 44 | path = "." + sep + "userfile" + sep + name + "qiandu" + sep + req.getParameter("dir") + file; 45 | } 46 | 47 | File f = new File(path); 48 | if(f.exists()){ 49 | FileInputStream fis = new FileInputStream(f); 50 | String filename=URLEncoder.encode(f.getName(),"utf-8"); //解决中文文件名下载后乱码的问题 51 | 52 | byte[] b = new byte[fis.available()]; 53 | fis.read(b); 54 | res.setCharacterEncoding("utf-8"); 55 | res.setHeader("Content-Disposition","attachment; filename="+filename+""); 56 | //获取响应报文输出流对象 57 | ServletOutputStream out =res.getOutputStream(); 58 | //输出 59 | out.write(b); 60 | out.flush(); 61 | out.close(); 62 | } 63 | 64 | 65 | 66 | 67 | } 68 | 69 | public void doPost(HttpServletRequest req, HttpServletResponse res) 70 | throws ServletException, IOException { 71 | 72 | this.doGet(req, res); 73 | 74 | } 75 | } 76 | 77 | -------------------------------------------------------------------------------- /pan_db.sql: -------------------------------------------------------------------------------- 1 | /* 2 | Navicat Premium Data Transfer 3 | 4 | Source Server : mysql 5 | Source Server Type : MySQL 6 | Source Server Version : 80021 7 | Source Host : localhost:3306 8 | Source Schema : pan_db 9 | 10 | Target Server Type : MySQL 11 | Target Server Version : 80021 12 | File Encoding : 65001 13 | 14 | Date: 05/11/2021 10:04:57 15 | */ 16 | 17 | SET NAMES utf8mb4; 18 | SET FOREIGN_KEY_CHECKS = 0; 19 | 20 | -- ---------------------------- 21 | -- Table structure for publicshare 22 | -- ---------------------------- 23 | DROP TABLE IF EXISTS `publicshare`; 24 | CREATE TABLE `publicshare` ( 25 | `name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL, 26 | `path` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL, 27 | `filename` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL, 28 | `size` int(0) NULL DEFAULT NULL, 29 | `uploadt` date NULL DEFAULT NULL, 30 | `ext` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL, 31 | PRIMARY KEY (`name`, `path`, `filename`) USING BTREE 32 | ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = Dynamic; 33 | 34 | -- ---------------------------- 35 | -- Table structure for userfile 36 | -- ---------------------------- 37 | DROP TABLE IF EXISTS `userfile`; 38 | CREATE TABLE `userfile` ( 39 | `name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL, 40 | `path` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL, 41 | `filename` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL, 42 | `size` int(0) NULL DEFAULT NULL, 43 | `uploadt` date NULL DEFAULT NULL, 44 | `ext` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL, 45 | PRIMARY KEY (`name`, `path`, `filename`) USING BTREE 46 | ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = Dynamic; 47 | 48 | -- ---------------------------- 49 | -- Table structure for users 50 | -- ---------------------------- 51 | DROP TABLE IF EXISTS `users`; 52 | CREATE TABLE `users` ( 53 | `name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL, 54 | `pwd` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, 55 | `usedsize` int(0) NULL DEFAULT NULL, 56 | `sharecount` int(0) NULL DEFAULT NULL, 57 | PRIMARY KEY (`name`) USING BTREE 58 | ) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic; 59 | 60 | SET FOREIGN_KEY_CHECKS = 1; 61 | -------------------------------------------------------------------------------- /src/util/OperUtil.java: -------------------------------------------------------------------------------- 1 | package util; 2 | 3 | import java.io.File; 4 | import java.io.FileInputStream; 5 | import java.io.FileOutputStream; 6 | import java.io.IOException; 7 | import java.nio.channels.FileChannel; 8 | import java.nio.file.Files; 9 | import java.util.ArrayList; 10 | import java.util.List; 11 | 12 | import com.mchange.io.FileUtils; 13 | 14 | public class OperUtil { 15 | 16 | public static void delete(File directory) { 17 | if (!directory.isDirectory()){ 18 | directory.delete(); 19 | } else{ 20 | File [] files = directory.listFiles(); 21 | 22 | if (files.length == 0){ 23 | directory.delete(); 24 | return; 25 | } 26 | 27 | for (File file : files){ 28 | if (file.isDirectory()){ 29 | delete(file); 30 | } else { 31 | file.delete(); 32 | } 33 | } 34 | 35 | directory.delete(); 36 | return; 37 | } 38 | } 39 | 40 | public static boolean create(String path, String dirname) { 41 | String cpath = path+System.getProperty("file.separator")+dirname; 42 | 43 | File file = new File(cpath); 44 | boolean res = false; 45 | if (file.exists()){ 46 | return res; 47 | } 48 | try{ 49 | res = file.mkdir(); 50 | } catch (Exception e){ 51 | e.printStackTrace(); 52 | return res; 53 | } 54 | return res; 55 | } 56 | 57 | 58 | public static boolean share(String path, String filename, String dest) { 59 | String sep = System.getProperty("file.separator"); 60 | File source = new File(path+sep+filename); 61 | File tofile = new File(dest+sep+filename); 62 | if(tofile.exists()) { 63 | return false; 64 | } 65 | try { 66 | copyFile(source,dest); 67 | }catch (Exception e){ 68 | e.printStackTrace(); 69 | } 70 | return true; 71 | } 72 | 73 | public static void copyFile(File source,String dest )throws IOException{ 74 | //创建目的地文件夹 75 | File destfile = new File(dest); 76 | if(!destfile.exists()){ 77 | destfile.mkdir(); 78 | } 79 | //如果source是文件夹,则在目的地址中创建新的文件夹 80 | if(source.isDirectory()){ 81 | File file = new File(dest+System.getProperty("file.separator")+source.getName());//用目的地址加上source的文件夹名称,创建新的文件夹 82 | file.mkdir(); 83 | //得到source文件夹的所有文件及目录 84 | File[] files = source.listFiles(); 85 | if(files.length==0){ 86 | return; 87 | }else{ 88 | for(int i = 0 ;i0 ) { 81 | OperUtil.delete(new File(userpath)); 82 | 83 | out.println(""); 85 | } else { 86 | out.println(""); 88 | } 89 | } catch (Exception e) { 90 | e.printStackTrace(); 91 | } 92 | 93 | break; 94 | case "update": 95 | try { 96 | if (userService.updatePwd(name, req.getParameter("pwd")) > 0) { 97 | out.println(""); 99 | } else { 100 | out.println(""); 102 | } 103 | } catch (Exception e) { 104 | e.printStackTrace(); 105 | } 106 | break; 107 | } 108 | 109 | } 110 | 111 | public void doPost(HttpServletRequest req, HttpServletResponse res) 112 | throws ServletException, IOException { 113 | 114 | this.doGet(req, res); 115 | 116 | } 117 | 118 | } 119 | -------------------------------------------------------------------------------- /src/service/impl/UserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package service.impl; 2 | 3 | import java.util.Date; 4 | import java.util.List; 5 | 6 | import dao.UserDao; 7 | import dao.impl.UserDaoImpl; 8 | import exception.IdIsNullException; 9 | import model.Users; 10 | import service.UserService; 11 | 12 | public class UserServiceImpl implements UserService { 13 | 14 | UserDao userDao = new UserDaoImpl(); 15 | 16 | @Override 17 | public int addUser(Users users) { 18 | String username = users.getName(); 19 | String pwd = users.getPwd(); 20 | 21 | 22 | return userDao.addUser(users); 23 | } 24 | 25 | @Override 26 | public int delUserById(String id) throws IdIsNullException { 27 | int count = userDao.delUserById(id); 28 | if (count == 1) { 29 | return 1; 30 | } 31 | return 0; 32 | } 33 | 34 | @Override 35 | public int updateUserById(Users users) throws IdIsNullException { 36 | // TODO Auto-generated method stub 37 | return userDao.updateUserById(users); 38 | } 39 | 40 | @Override 41 | public boolean checkUser(Users users) { 42 | 43 | return userDao.checkUser(users); 44 | 45 | } 46 | 47 | @Override 48 | public List getShareFile(String name) { 49 | return userDao.getShareFile(name); 50 | } 51 | 52 | @Override 53 | public int deleteFile(String path, String filename) { 54 | return userDao.deleteFile(path, filename); 55 | } 56 | 57 | @Override 58 | public int insertFile(String name, String path, String filename, long size, Date uploadt, String ext) { 59 | return userDao.insertFile(name, path, filename, size, uploadt, ext); 60 | } 61 | 62 | @Override 63 | public String getOwner(String path, String filename) { 64 | return userDao.getOwner(path, filename); 65 | } 66 | 67 | @Override 68 | public List getAllName() { 69 | return userDao.getAllName(); 70 | } 71 | 72 | @Override 73 | public int insertHome(String name, String path, String filename, long size, Date uploadt, String ext) { 74 | return userDao.insertHome(name, path, filename, size, uploadt, ext); 75 | } 76 | 77 | @Override 78 | public int deleteHome(String name, String path, String filename) { 79 | return userDao.deleteHome(name, path, filename); 80 | } 81 | 82 | @Override 83 | public int updateHome(String name, String path, String filename, String newfilename) { 84 | return userDao.updateHome(name, path, filename, newfilename); 85 | } 86 | 87 | @Override 88 | public List FindHome(String name, String key) { 89 | return userDao.FindHome(name, key); 90 | } 91 | 92 | @Override 93 | public List FindHomeShare(String name, String key) { 94 | return userDao.FindHomeShare(name, key); 95 | } 96 | 97 | @Override 98 | public List FindPublicShare(String key) { 99 | return userDao.FindPublicShare(key); 100 | } 101 | 102 | @Override 103 | public boolean checkAdminUser(Users users) { 104 | 105 | return userDao.checkAdminUser(users); 106 | 107 | } 108 | 109 | @Override 110 | public List selectAll() { 111 | return userDao.selectAll(); 112 | } 113 | 114 | @Override 115 | public int delUserByName(String name) throws IdIsNullException { 116 | int count = userDao.delUserByName(name); 117 | if (count == 1) { 118 | return 1; 119 | } 120 | return 0; 121 | } 122 | 123 | @Override 124 | public List selectRenamePath(String path, String dirname) { 125 | return userDao.selectRenamePath(path, dirname); 126 | } 127 | 128 | @Override 129 | public int delShareDir(String path, String dirname) throws IdIsNullException { 130 | return userDao.delShareDir(path, dirname); 131 | } 132 | 133 | @Override 134 | public int updatePwd(String name, String pwd) throws IdIsNullException { 135 | return userDao.updatePwd(name, pwd); 136 | } 137 | 138 | @Override 139 | public List findUser(String key) { 140 | return userDao.findUser(key); 141 | } 142 | } -------------------------------------------------------------------------------- /src/service/UserService.java: -------------------------------------------------------------------------------- 1 | package service; 2 | 3 | import java.util.Date; 4 | import java.util.List; 5 | 6 | import exception.IdIsNullException; 7 | import model.Users; 8 | 9 | public interface UserService { 10 | 11 | /** 12 | * 添加单个用户 13 | * @param users 14 | * @return 影响的记录数 15 | */ 16 | public int addUser(Users users); 17 | 18 | /** 19 | * 根据id删除单个用户 20 | * @param id 21 | * @return 影响的记录数 22 | * @throws IdIsNullException 23 | */ 24 | public int delUserById(String id) throws IdIsNullException; 25 | 26 | /** 27 | * 修改单个用户 28 | * @param users 29 | * @return 影响的记录数 30 | * @throws IdIsNullException 31 | */ 32 | public int updateUserById(Users users) throws IdIsNullException; 33 | 34 | /** 35 | * 检查用户是否存在且密码是否匹配 36 | * @param users 37 | * @return 38 | */ 39 | public boolean checkUser(Users users); 40 | 41 | /** 42 | * 获取某用户的全部分享文件名列表 43 | * @param name 44 | * @return List 45 | */ 46 | public List getShareFile(String name); 47 | 48 | /** 49 | * 根据路径和文件名删除文件信息 50 | * @param path, filename 51 | * @return 影响的记录数 52 | */ 53 | public int deleteFile(String path, String filename); 54 | 55 | /** 56 | * 插入一条共享文件信息 57 | * @param name, path, filename 58 | * @return 影响的记录数 59 | */ 60 | public int insertFile(String name, String path, String filename, long size, Date uploadt, String ext); 61 | 62 | /** 63 | * 根据path和filename查询所有者 64 | * @param name, path, filename 65 | * @return name 66 | */ 67 | public String getOwner(String path, String filename); 68 | 69 | /** 70 | * 获取所有用户名字列表 71 | * @param 72 | * @return List 73 | */ 74 | public List getAllName(); 75 | 76 | /** 77 | * 插入一条用户文件信息 78 | * @param name, path, filename, size, uploadt, ext 79 | * @return 影响的记录数 80 | */ 81 | public int insertHome(String name, String path, String filename, long size, Date uploadt, String ext); 82 | 83 | /** 84 | * 删除一条用户文件信息 85 | * @param name, path, filename 86 | * @return 影响的记录数 87 | */ 88 | public int deleteHome(String name, String path, String filename); 89 | 90 | /** 91 | * 更改一条用户文件信息 92 | * @param name, path, filename, newfilename 93 | * @return 影响的记录数 94 | */ 95 | public int updateHome(String name, String path, String filename, String newfilename); 96 | 97 | /** 98 | * 搜索含有key的用户文件信息 99 | * @param name, key 100 | * @return 影响的记录数 101 | */ 102 | public List FindHome(String name, String key); 103 | 104 | /** 105 | * 搜索含有key的用户共享文件信息 106 | * @param name, key 107 | * @return 影响的记录数 108 | */ 109 | public List FindHomeShare(String name, String key); 110 | 111 | /** 112 | * 搜索含有key的公共共享文件信息 113 | * @param key 114 | * @return 影响的记录数 115 | */ 116 | public List FindPublicShare(String key); 117 | 118 | /** 119 | * 检查管理员是否存在且密码是否匹配 120 | * @param users 121 | * @return 122 | */ 123 | public boolean checkAdminUser(Users users); 124 | 125 | /** 126 | *查询数据库所有用户数据 127 | * @param 128 | * @return 用户信息二维数组 129 | */ 130 | public List selectAll(); 131 | 132 | /** 133 | * 根据name删除单个用户 134 | * @param name 135 | * @return 影响的记录数 136 | * @throws IdIsNullException 137 | */ 138 | public int delUserByName(String name) throws IdIsNullException; 139 | 140 | /** 141 | *查询数据库需要重命名的记录 142 | * @param 143 | * @return 记录的path构成的数组 144 | */ 145 | public List selectRenamePath(String path, String dirname); 146 | 147 | /** 148 | * 删除共享目录下所有文件 149 | * @param path, dirname 150 | * @return 影响的记录数 151 | * @throws IdIsNullException 152 | */ 153 | public int delShareDir(String path, String dirname) throws IdIsNullException; 154 | 155 | /** 156 | * 修改单个用户密码 157 | * @param name, pwd 158 | * @return 影响的记录数 159 | * @throws IdIsNullException 160 | */ 161 | public int updatePwd(String name, String pwd) throws IdIsNullException; 162 | 163 | /** 164 | *模糊查询用户 165 | * @param key 166 | * @return 用户信息二维数组 167 | */ 168 | public List findUser(String key); 169 | } 170 | 171 | -------------------------------------------------------------------------------- /src/dao/UserDao.java: -------------------------------------------------------------------------------- 1 | package dao; 2 | 3 | import java.util.Date; 4 | import java.util.List; 5 | 6 | import exception.IdIsNullException; 7 | import model.Users; 8 | 9 | public interface UserDao { 10 | 11 | /** 12 | * 添加单个用户 13 | * @param users 14 | * @return 影响的记录数 15 | */ 16 | public int addUser(Users users); 17 | 18 | /** 19 | * 根据id删除单个用户 20 | * @param id 21 | * @return 影响的记录数 22 | * @throws IdIsNullException 23 | */ 24 | public int delUserById(String id) throws IdIsNullException; 25 | 26 | /** 27 | * 修改单个用户 28 | * @param users 29 | * @return 影响的记录数 30 | * @throws IdIsNullException 31 | */ 32 | public int updateUserById(Users users) throws IdIsNullException; 33 | 34 | /** 35 | * 检查用户是否存在且密码是否匹配 36 | * @param users 37 | * @return 38 | */ 39 | public boolean checkUser(Users users); 40 | 41 | /** 42 | * 获取某用户的全部分享文件名和分享路径列表 43 | * @param name 44 | * @return List 45 | */ 46 | public List getShareFile(String name); 47 | 48 | /** 49 | * 根据路径和文件名删除文件信息 50 | * @param path, filename 51 | * @return 影响的记录数 52 | */ 53 | public int deleteFile(String path, String filename); 54 | 55 | /** 56 | * 插入一条共享文件信息 57 | * @param name, path, filename 58 | * @return 影响的记录数 59 | */ 60 | public int insertFile(String name, String path, String filename, long size, Date uploadt, String ext); 61 | 62 | /** 63 | * 根据path和filename查询所有者 64 | * @param name, path, filename 65 | * @return name 66 | */ 67 | public String getOwner(String path, String filename); 68 | 69 | /** 70 | * 获取所有用户名字列表 71 | * @param 72 | * @return List 73 | */ 74 | public List getAllName(); 75 | 76 | /** 77 | * 插入一条用户文件信息 78 | * @param name, path, filename, size, uploadt, ext 79 | * @return 影响的记录数 80 | */ 81 | public int insertHome(String name, String path, String filename, long size, Date uploadt, String ext); 82 | 83 | /** 84 | * 删除一条用户文件信息 85 | * @param name, path, filename 86 | * @return 影响的记录数 87 | */ 88 | public int deleteHome(String name, String path, String filename); 89 | 90 | /** 91 | * 更改一条用户文件信息 92 | * @param name, path, filename, newfilename 93 | * @return 影响的记录数 94 | */ 95 | public int updateHome(String name, String path, String filename, String newfilename); 96 | 97 | /** 98 | * 搜索含有key的用户文件信息 99 | * @param name, key 100 | * @return 影响的记录数 101 | */ 102 | public List FindHome(String name, String key); 103 | 104 | /** 105 | * 搜索含有key的用户共享文件信息 106 | * @param name, key 107 | * @return 影响的记录数 108 | */ 109 | public List FindHomeShare(String name, String key); 110 | 111 | /** 112 | * 搜索含有key的公共共享文件信息 113 | * @param key 114 | * @return 影响的记录数 115 | */ 116 | public List FindPublicShare(String key); 117 | 118 | /** 119 | * 检查管理员是否存在且密码是否匹配 120 | * @param users 121 | * @return 122 | */ 123 | public boolean checkAdminUser(Users users); 124 | 125 | /** 126 | *查询数据库所有用户数据 127 | * @param 128 | * @return 用户信息二维数组 129 | */ 130 | public List selectAll(); 131 | 132 | /** 133 | * 根据name删除单个用户 134 | * @param name 135 | * @return 影响的记录数 136 | * @throws IdIsNullException 137 | */ 138 | public int delUserByName(String name) throws IdIsNullException; 139 | 140 | /** 141 | * 修改公共文件夹名 142 | * @param path, dirname 143 | * @return 影响的记录数 144 | * @throws IdIsNullException 145 | */ 146 | public int updateShareDir(String path, String dirname) throws IdIsNullException; 147 | 148 | /** 149 | *查询数据库需要重命名的记录 150 | * @param 151 | * @return 记录的path构成的数组 152 | */ 153 | public List selectRenamePath(String path, String dirname); 154 | 155 | /** 156 | * 删除共享目录下所有文件 157 | * @param path, dirname 158 | * @return 影响的记录数 159 | * @throws IdIsNullException 160 | */ 161 | public int delShareDir(String path, String dirname) throws IdIsNullException; 162 | 163 | /** 164 | * 修改单个用户密码 165 | * @param name, pwd 166 | * @return 影响的记录数 167 | * @throws IdIsNullException 168 | */ 169 | public int updatePwd(String name, String pwd) throws IdIsNullException; 170 | 171 | /** 172 | *模糊查询用户 173 | * @param key 174 | * @return 用户信息二维数组 175 | */ 176 | public List findUser(String key); 177 | 178 | 179 | 180 | 181 | 182 | } 183 | -------------------------------------------------------------------------------- /src/controller/MyShare.java: -------------------------------------------------------------------------------- 1 | package controller; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | import java.io.PrintWriter; 6 | import java.text.DateFormat; 7 | 8 | import javax.servlet.ServletException; 9 | import javax.servlet.annotation.MultipartConfig; 10 | import javax.servlet.http.HttpServlet; 11 | import javax.servlet.http.HttpServletRequest; 12 | import javax.servlet.http.HttpServletResponse; 13 | import javax.servlet.http.HttpSession; 14 | 15 | import service.UserService; 16 | import service.impl.UserServiceImpl; 17 | 18 | import java.util.ArrayList; 19 | import java.util.Date; 20 | import java.util.List; 21 | 22 | import util.FileUtil; 23 | import util.OperUtil; 24 | 25 | @MultipartConfig //使用MultipartConfig注解标注改servlet能够接受文件上传的请求 26 | public class MyShare extends HttpServlet { 27 | 28 | UserService userService = new UserServiceImpl(); 29 | 30 | public void doGet(HttpServletRequest req, HttpServletResponse res) 31 | throws ServletException, IOException { 32 | 33 | req.setCharacterEncoding("utf-8"); 34 | res.setContentType("text/html;charset=utf-8"); 35 | 36 | String method = (req.getParameter("method")!=null)?req.getParameter("method"):""; 37 | 38 | switch (method) { 39 | case "delete": 40 | Page(req, res, method); 41 | break; 42 | default: 43 | mainPage(req, res); 44 | break; 45 | 46 | } 47 | 48 | } 49 | 50 | 51 | 52 | 53 | 54 | private void mainPage(HttpServletRequest req, HttpServletResponse res) 55 | throws ServletException, IOException { 56 | HttpSession session = req.getSession(); 57 | String name = null; 58 | String sep = System.getProperty("file.separator"); 59 | 60 | if(!session.isNew() && session.getAttribute("name") != null){ 61 | name = (String)session.getAttribute("name"); 62 | } else { 63 | res.sendRedirect("./Login"); 64 | return; 65 | } 66 | List mysharelist = userService.getShareFile(name); 67 | 68 | String sharepath = "." + sep + "publicshare"; 69 | 70 | ArrayList mysharetotal = new ArrayList(); //存放用户目录下的目录信息列表 71 | 72 | if (mysharelist != null) { 73 | for (List add : mysharelist) { 74 | String i = sharepath + add.get(0) + add.get(1); 75 | ArrayList info = new ArrayList(); 76 | File f = new File(i); 77 | Double size = f.length()/1024.0; 78 | DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG,DateFormat.LONG); 79 | info.add(f.getName()); 80 | info.add((String)add.get(0)); 81 | info.add(dateFormat.format(new Date(f.lastModified()))); 82 | if (size < 1024) { 83 | info.add(String.format("%.2fKB", size)); 84 | } else { 85 | info.add(String.format("%.2fMB", size/1024.0)); 86 | } 87 | info.add(FileUtil.ext(i)); 88 | mysharetotal.add(info); 89 | 90 | } 91 | } 92 | 93 | req.setAttribute("mysharetotal", mysharetotal); 94 | req.setAttribute("name", name); 95 | req.getRequestDispatcher("/MyShareView").forward(req, res); 96 | } 97 | 98 | 99 | 100 | private void Page(HttpServletRequest req, HttpServletResponse res, String method) 101 | throws ServletException, IOException { 102 | HttpSession session = req.getSession(); 103 | String name = null; 104 | String sep = System.getProperty("file.separator"); 105 | PrintWriter out = res.getWriter(); 106 | String path = req.getParameter("path"); 107 | String filename = req.getParameter("name"); 108 | 109 | if(!session.isNew() && session.getAttribute("name") != null){ 110 | name = (String)session.getAttribute("name"); 111 | } else { 112 | res.sendRedirect("./Login"); 113 | return; 114 | } 115 | 116 | String userpath = "." + sep + "publicshare" + path; 117 | switch (method) { 118 | 119 | case "delete": 120 | if (userService.deleteFile(path, filename) > 0) { 121 | OperUtil.delete(new File(userpath+req.getParameter("name"))); 122 | out.println(""); 124 | 125 | } else { 126 | out.println(""); 128 | } 129 | break; 130 | } 131 | 132 | 133 | 134 | } 135 | 136 | 137 | 138 | public void doPost(HttpServletRequest req, HttpServletResponse res) 139 | throws ServletException, IOException { 140 | 141 | this.doGet(req, res); 142 | 143 | } 144 | 145 | } 146 | -------------------------------------------------------------------------------- /src/controller/FindFile.java: -------------------------------------------------------------------------------- 1 | package controller; 2 | 3 | import java.io.IOException; 4 | 5 | import javax.servlet.ServletException; 6 | import javax.servlet.http.HttpServlet; 7 | import javax.servlet.http.HttpServletRequest; 8 | import javax.servlet.http.HttpServletResponse; 9 | import javax.servlet.http.HttpSession; 10 | 11 | import service.UserService; 12 | import service.impl.UserServiceImpl; 13 | 14 | import java.util.ArrayList; 15 | import java.util.List; 16 | 17 | 18 | public class FindFile extends HttpServlet { 19 | 20 | UserService userService = new UserServiceImpl(); 21 | 22 | public void doGet(HttpServletRequest req, HttpServletResponse res) 23 | throws ServletException, IOException { 24 | 25 | req.setCharacterEncoding("utf-8"); 26 | res.setContentType("text/html;charset=utf-8"); 27 | 28 | String target = (req.getParameter("target")!=null)?req.getParameter("target"):""; 29 | req.setAttribute("target", target); 30 | switch (target) { 31 | case "home": 32 | home(req, res); 33 | break; 34 | case "myshare": 35 | myShare(req, res); 36 | break; 37 | case "publicshare": 38 | publicShare(req, res); 39 | break; 40 | 41 | case "any": 42 | any(req, res); 43 | break; 44 | default: 45 | break; 46 | 47 | } 48 | 49 | } 50 | 51 | private void home(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { 52 | 53 | HttpSession session = req.getSession(); 54 | String key = (req.getParameter("key")!=null)?req.getParameter("key"):""; 55 | String name = null; 56 | List filetotal = new ArrayList(); 57 | 58 | if(!session.isNew() && session.getAttribute("name") != null){ 59 | name = (String)session.getAttribute("name"); 60 | } else { 61 | res.sendRedirect("./Login"); 62 | return; 63 | } 64 | 65 | if (!key.equals("") && (filetotal=userService.FindHome(name, key)) != null ) { 66 | req.setAttribute("filetotal", filetotal); 67 | } 68 | req.setAttribute("name", name); 69 | req.getRequestDispatcher("/FindFileView").forward(req, res); 70 | 71 | 72 | 73 | } 74 | 75 | 76 | 77 | 78 | 79 | private void myShare(HttpServletRequest req, HttpServletResponse res) 80 | throws ServletException, IOException { 81 | HttpSession session = req.getSession(); 82 | String key = (req.getParameter("key")!=null)?req.getParameter("key"):""; 83 | String name = null; 84 | List filetotal = new ArrayList(); 85 | 86 | if(!session.isNew() && session.getAttribute("name") != null){ 87 | name = (String)session.getAttribute("name"); 88 | } else { 89 | res.sendRedirect("./Login"); 90 | return; 91 | } 92 | 93 | if (!key.equals("") && (filetotal=userService.FindHomeShare(name, key)) != null ) { 94 | req.setAttribute("filetotal", filetotal); 95 | } 96 | req.setAttribute("name", name); 97 | req.getRequestDispatcher("/FindFileView").forward(req, res); 98 | } 99 | 100 | 101 | 102 | private void publicShare(HttpServletRequest req, HttpServletResponse res) 103 | throws ServletException, IOException { 104 | HttpSession session = req.getSession(); 105 | String key = (req.getParameter("key")!=null)?req.getParameter("key"):""; 106 | String name = null; 107 | List filetotal = new ArrayList(); 108 | 109 | if(!session.isNew() && session.getAttribute("name") != null){ 110 | name = (String)session.getAttribute("name"); 111 | } else { 112 | res.sendRedirect("./Login"); 113 | return; 114 | } 115 | 116 | if (!key.equals("") && (filetotal=userService.FindPublicShare(key)) != null ) { 117 | req.setAttribute("filetotal", filetotal); 118 | } 119 | req.setAttribute("name", name); 120 | req.getRequestDispatcher("/FindFileView").forward(req, res); 121 | 122 | 123 | 124 | } 125 | 126 | private void any(HttpServletRequest req, HttpServletResponse res) 127 | throws ServletException, IOException { 128 | String name = req.getParameter("username"); 129 | HttpSession session = req.getSession(); 130 | if(!session.isNew() && session.getAttribute("name") != null) { 131 | if(session.getAttribute("name").equals("admin")){ 132 | ; 133 | } else { 134 | res.sendRedirect("./Login"); 135 | return; 136 | } 137 | } else { 138 | res.sendRedirect("./Login"); 139 | return; 140 | } 141 | String key = (req.getParameter("key")!=null)?req.getParameter("key"):""; 142 | List filetotal = new ArrayList(); 143 | 144 | 145 | if (!key.equals("") && (filetotal=userService.FindHome(name, key)) != null ) { 146 | req.setAttribute("filetotal", filetotal); 147 | } 148 | req.setAttribute("name", name); 149 | req.getRequestDispatcher("/FindAnyView").forward(req, res); 150 | 151 | 152 | 153 | } 154 | 155 | 156 | 157 | public void doPost(HttpServletRequest req, HttpServletResponse res) 158 | throws ServletException, IOException { 159 | 160 | this.doGet(req, res); 161 | 162 | } 163 | 164 | 165 | 166 | } 167 | -------------------------------------------------------------------------------- /src/controller/PublicShare.java: -------------------------------------------------------------------------------- 1 | package controller; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | import java.text.DateFormat; 6 | 7 | import javax.servlet.ServletException; 8 | import javax.servlet.annotation.MultipartConfig; 9 | import javax.servlet.http.HttpServlet; 10 | import javax.servlet.http.HttpServletRequest; 11 | import javax.servlet.http.HttpServletResponse; 12 | import javax.servlet.http.HttpSession; 13 | 14 | import service.UserService; 15 | import service.impl.UserServiceImpl; 16 | 17 | import java.util.ArrayList; 18 | import java.util.Date; 19 | 20 | import util.FileUtil; 21 | 22 | @MultipartConfig //使用MultipartConfig注解标注改servlet能够接受文件上传的请求 23 | public class PublicShare extends HttpServlet { 24 | 25 | UserService userService = new UserServiceImpl(); 26 | 27 | public void doGet(HttpServletRequest req, HttpServletResponse res) 28 | throws ServletException, IOException { 29 | 30 | req.setCharacterEncoding("utf-8"); 31 | res.setContentType("text/html;charset=utf-8"); 32 | 33 | String method = (req.getParameter("method")!=null)?req.getParameter("method"):""; 34 | 35 | switch (method) { 36 | case "upload": 37 | uploadPage(req, res); 38 | break; 39 | 40 | default: 41 | mainPage(req, res); 42 | break; 43 | 44 | } 45 | 46 | } 47 | 48 | private void uploadPage(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { 49 | 50 | HttpSession session = req.getSession(); 51 | String name = null; 52 | String sep = System.getProperty("file.separator"); 53 | String dir = null; 54 | if (req.getParameter("dir")==null || req.getParameter("dir").equals("")) { 55 | dir = sep; 56 | } else { 57 | dir = (String)req.getParameter("dir"); 58 | } 59 | 60 | if(!session.isNew() && session.getAttribute("name") != null){ 61 | name = (String)session.getAttribute("name"); 62 | } else { 63 | res.sendRedirect("./Login"); 64 | return; 65 | } 66 | 67 | String userpath = "." + sep + "publicshare" + dir; 68 | req.setAttribute("username", name); 69 | req.setAttribute("path", dir); 70 | req.setAttribute("uploadpath", userpath); 71 | req.setAttribute("part", req.getPart("uploadfile")); 72 | req.getRequestDispatcher("/Upload").forward(req, res); 73 | 74 | 75 | 76 | 77 | } 78 | 79 | 80 | 81 | private void mainPage(HttpServletRequest req, HttpServletResponse res) 82 | throws ServletException, IOException { 83 | HttpSession session = req.getSession(); 84 | String name = null; 85 | String sep = System.getProperty("file.separator"); 86 | String dir = null; 87 | if (req.getParameter("dir")==null || req.getParameter("dir").equals("")) { 88 | dir = sep; 89 | } else { 90 | dir = (String)req.getParameter("dir"); 91 | } 92 | 93 | if(!session.isNew() && session.getAttribute("name") != null){ 94 | name = (String)session.getAttribute("name"); 95 | } else { 96 | res.sendRedirect("./Login"); 97 | return; 98 | } 99 | 100 | String userpath = "." + sep + "publicshare" + dir; 101 | 102 | ArrayList dirtotal = new ArrayList(); //存放用户目录下的目录信息列表 103 | ArrayList filetotal = new ArrayList(); //存放用户目录下的文件信息列表 104 | 105 | for (String i:FileUtil.getFiles(userpath)) { 106 | ArrayList info = new ArrayList(); 107 | File f = new File(i); 108 | String n = f.getName(); 109 | Double size = f.length()/1024.0; 110 | DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG,DateFormat.LONG); 111 | info.add(n); 112 | info.add(userService.getOwner(dir, n)); 113 | info.add(dateFormat.format(new Date(f.lastModified()))); 114 | if (size < 1024) { 115 | info.add(String.format("%.2fKB", size)); 116 | } else { 117 | info.add(String.format("%.2fMB", size/1024.0)); 118 | } 119 | info.add(FileUtil.ext(i)); 120 | filetotal.add(info); 121 | 122 | } 123 | 124 | 125 | for (String i:FileUtil.getDirs(userpath)) { 126 | ArrayList info = new ArrayList(); 127 | File f = new File(i); 128 | DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG,DateFormat.LONG); 129 | long size = FileUtil.getTotalSizeOfFilesInDir(f)/1024; 130 | info.add(f.getName()); 131 | info.add(dateFormat.format(new Date(f.lastModified()))); 132 | if (size < 1024) { 133 | info.add(String.format("%dKB", size)); 134 | } else { 135 | info.add(String.format("%.2fMB", size/1024.0)); 136 | } 137 | info.add("DIR"); 138 | dirtotal.add(info); 139 | 140 | } 141 | 142 | req.setAttribute("filetotal", filetotal); 143 | req.setAttribute("dirtotal", dirtotal); 144 | req.setAttribute("dir", dir); 145 | req.setAttribute("name", name); 146 | req.getRequestDispatcher("/PublicShareView").forward(req, res); 147 | } 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | public void doPost(HttpServletRequest req, HttpServletResponse res) 156 | throws ServletException, IOException { 157 | 158 | this.doGet(req, res); 159 | 160 | } 161 | 162 | } 163 | -------------------------------------------------------------------------------- /src/controller/Upload.java: -------------------------------------------------------------------------------- 1 | package controller; 2 | 3 | import java.io.FileOutputStream; 4 | import java.io.IOException; 5 | import java.io.InputStream; 6 | import java.io.PrintWriter; 7 | import java.net.URLEncoder; 8 | import java.util.Date; 9 | import java.util.regex.Matcher; 10 | import java.util.regex.Pattern; 11 | 12 | import javax.servlet.ServletException; 13 | import javax.servlet.annotation.MultipartConfig; 14 | import javax.servlet.http.HttpServlet; 15 | import javax.servlet.http.HttpServletRequest; 16 | import javax.servlet.http.HttpServletResponse; 17 | import javax.servlet.http.HttpSession; 18 | import javax.servlet.http.Part; 19 | 20 | import service.UserService; 21 | import service.impl.UserServiceImpl; 22 | import util.FileUtil; 23 | 24 | 25 | @MultipartConfig //使用MultipartConfig注解标注改servlet能够接受文件上传的请求 26 | public class Upload extends HttpServlet { 27 | 28 | UserService userService = new UserServiceImpl(); 29 | 30 | public void doGet(HttpServletRequest req, HttpServletResponse res) 31 | throws ServletException, IOException, IllegalStateException { 32 | req.setCharacterEncoding("utf-8"); 33 | res.setContentType("text/html;charset=utf-8"); 34 | PrintWriter out = res.getWriter(); 35 | String name = null; 36 | 37 | String uploadpath = (String) req.getAttribute("uploadpath"); 38 | HttpSession session = req.getSession(); 39 | 40 | if(!session.isNew() && session.getAttribute("name") != null) { 41 | name = (String)session.getAttribute("name"); 42 | } else { 43 | res.sendRedirect("./Login"); 44 | return; 45 | } 46 | 47 | Part part = (Part) req.getAttribute("part"); 48 | String disposition = part.getHeader("Content-Disposition"); 49 | Matcher m = Pattern.compile(".*filename=\"(.*\\..*)\"").matcher(disposition); 50 | 51 | if (m.find()) { 52 | disposition = m.group(1); 53 | InputStream is = part.getInputStream(); 54 | FileOutputStream fos = new FileOutputStream(uploadpath+disposition); 55 | long size = part.getSize(); 56 | String ext = FileUtil.ext(disposition); 57 | if (req.getAttribute("username") != null) { 58 | if (userService.insertFile((String)req.getAttribute("username"), (String)req.getAttribute("path"), disposition, size, new Date(), ext) > 0) { 59 | byte[] bty = new byte[1024]; 60 | int length =0; 61 | while((length=is.read(bty))!=-1){ 62 | fos.write(bty,0,length); 63 | } 64 | fos.close(); 65 | is.close(); 66 | String dir = URLEncoder.encode((String)req.getAttribute("path"), "UTF-8"); 67 | if (name.equals("admin")) { 68 | out.println(""); 70 | }else { 71 | out.println(""); 73 | } 74 | } else { 75 | 76 | String dir = URLEncoder.encode((String)req.getAttribute("path"), "UTF-8"); 77 | if (name.equals("admin")) { 78 | out.println(""); 80 | }else { 81 | out.println(""); 83 | } 84 | 85 | } 86 | 87 | } else { 88 | 89 | if (userService.insertHome((String)req.getAttribute("ownname"), (String)req.getAttribute("path"), disposition, size, new Date(), ext) > 0) { 90 | byte[] bty = new byte[1024]; 91 | int length =0; 92 | while((length=is.read(bty))!=-1){ 93 | fos.write(bty,0,length); 94 | } 95 | fos.close(); 96 | is.close(); 97 | 98 | String dir = URLEncoder.encode((String)req.getAttribute("path"), "UTF-8"); 99 | if (name.equals("admin")) { 100 | out.println(""); 102 | } else { 103 | out.println(""); 105 | } 106 | } else { 107 | String dir = URLEncoder.encode((String)req.getAttribute("path"), "UTF-8"); 108 | if (name.equals("admin")) { 109 | out.println(""); 111 | } else { 112 | out.println(""); 114 | } 115 | 116 | } 117 | 118 | } 119 | 120 | } 121 | 122 | 123 | 124 | } 125 | 126 | public void doPost(HttpServletRequest req, HttpServletResponse res) 127 | throws ServletException, IOException { 128 | 129 | this.doGet(req, res); 130 | 131 | } 132 | } 133 | -------------------------------------------------------------------------------- /src/view/Register.java: -------------------------------------------------------------------------------- 1 | package view; 2 | 3 | import java.io.IOException; 4 | import java.io.PrintWriter; 5 | 6 | import javax.servlet.ServletException; 7 | import javax.servlet.http.HttpServlet; 8 | import javax.servlet.http.HttpServletRequest; 9 | import javax.servlet.http.HttpServletResponse; 10 | 11 | public class Register extends HttpServlet { 12 | 13 | public void doGet(HttpServletRequest req, HttpServletResponse res) 14 | throws ServletException, IOException { 15 | req.setCharacterEncoding("utf-8"); 16 | res.setContentType("text/html;charset=utf-8"); 17 | PrintWriter out = res.getWriter(); 18 | out.print("\r\n" + 19 | "\r\n" + 20 | "\r\n" + 21 | " \r\n" + 22 | " register\r\n" + 23 | " \r\n" + 24 | " \r\n" + 64 | "\r\n" + 65 | "\r\n" + 66 | "\r\n" + 67 | " \r\n" + 68 | "
\r\n" + 69 | "
\r\n" + 70 | "

用户注册

\r\n" + 71 | "
\r\n" + 72 | " \r\n" + 73 | "
\r\n" + 74 | " \r\n" + 75 | "
\r\n" + 76 | "
\r\n" + 77 | "\r\n" + 78 | "
\r\n" + 79 | " \r\n" + 80 | "
\r\n" + 81 | " \r\n" + 82 | "
\r\n" + 83 | "
\r\n" + 84 | "\r\n" + 85 | "
\r\n" + 86 | " \r\n" + 87 | "
\r\n" + 88 | " \r\n" + 89 | "
\r\n" + 90 | "
\r\n" + 91 | " \r\n" + 92 | " \r\n" + 93 | "
\r\n" + 94 | " \r\n" + 95 | "
\r\n" + 96 | " \r\n" + 98 | "
\r\n" + 99 | "
\r\n" + 100 | "
\r\n" + 101 | " \r\n" + 102 | "\r\n" + 103 | "\r\n" + 104 | "\r\n" + 105 | ""); 106 | 107 | 108 | } 109 | 110 | public void doPost(HttpServletRequest req, HttpServletResponse res) 111 | throws ServletException, IOException { 112 | 113 | this.doGet(req, res); 114 | } 115 | 116 | } -------------------------------------------------------------------------------- /src/view/Login.java: -------------------------------------------------------------------------------- 1 | package view; 2 | 3 | import java.io.IOException; 4 | import java.io.PrintWriter; 5 | 6 | import javax.servlet.ServletException; 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 javax.servlet.http.HttpSession; 12 | 13 | public class Login extends HttpServlet { 14 | 15 | public void doGet(HttpServletRequest req, HttpServletResponse res) 16 | throws ServletException, IOException { 17 | req.setCharacterEncoding("utf-8"); 18 | res.setContentType("text/html;charset=utf-8"); 19 | PrintWriter out = res.getWriter(); 20 | HttpSession session = req.getSession(); 21 | Cookie cookie = null; 22 | String del = req.getParameter("del"); 23 | 24 | if (del != null) { 25 | 26 | session.invalidate(); 27 | res.sendRedirect("./Login"); 28 | 29 | } else { 30 | 31 | if(!session.isNew()){ 32 | if(session.getAttribute("name") != null){ 33 | res.sendRedirect("./LoginController"); 34 | } 35 | } 36 | 37 | String msg = (String) req.getAttribute("errMsg"); 38 | 39 | out.print("\r\n" + 40 | "\r\n" + 41 | "\r\n" + 42 | "\r\n" + 43 | " \r\n" + 44 | " \r\n" + 45 | " \r\n" + 46 | " Login\r\n" + 47 | "\r\n" + 48 | " \r\n" + 49 | " \r\n" + 64 | "\r\n" + 65 | "\r\n" + 66 | "\r\n" + 67 | "\r\n" + 68 | " \r\n" + 69 | "
\r\n" + 70 | " \r\n" + 71 | "
\r\n" + 72 | "

用户登录

\r\n" + 73 | "
\r\n" + 74 | " \r\n" + 75 | "
\r\n" + 76 | " \r\n" + 77 | " \r\n" + 79 | " \r\n" + 80 | " \r\n" + 81 | " \r\n" + 82 | "
\r\n" + 83 | "
\r\n" + 84 | "
\r\n" + 85 | " \r\n" + 86 | "
\r\n" + 87 | " \r\n" + 88 | " \r\n" + 90 | " \r\n" + 91 | " \r\n" + 92 | " \r\n" + 93 | "
\r\n" + 94 | "
\r\n" + 95 | "\r\n" + 96 | "
\r\n" + 97 | " 注册\r\n" + 98 | "
\r\n" + 99 | "
\r\n" + 100 | "
\r\n" + 101 | " 格式乱了,或者颜色不显示,请更换谷歌浏览器!!!\r\n" + 102 | "\r\n" + 103 | "\r\n" + 104 | "\r\n" + 105 | ""); 106 | if (msg != null) { 107 | out.println(msg); 108 | } 109 | } 110 | 111 | } 112 | 113 | public void doPost(HttpServletRequest req, HttpServletResponse res) 114 | throws ServletException, IOException { 115 | 116 | this.doGet(req, res); 117 | } 118 | 119 | } -------------------------------------------------------------------------------- /WebContent/css/style1.css: -------------------------------------------------------------------------------- 1 | @import url("https://fonts.googleapis.com/css?family=Roboto:400,700&display=swap"); 2 | :root { 3 | --space-root: 1rem; 4 | --space-xs: calc(var(--space-root) / 2); 5 | --space-s: calc(var(--space-root) / 1.5); 6 | --space-m: var(--space-root); 7 | --space-l: calc(var(--space-root) * 1.5); 8 | --space-xl: calc(var(--space-root) * 2); 9 | --color-primary: mediumslateblue; 10 | --color-secondary: black; 11 | --color-tertiary: hotpink; 12 | --base-border-radius: 0.25rem; 13 | --ease: cubic-bezier(0.075, 0.82, 0.165, 1); 14 | --duration: 350ms; 15 | --font-family: 'Roboto', sans-serif; 16 | --font-size: 1.25rem; 17 | } 18 | 19 | * { 20 | box-sizing: border-box; 21 | } 22 | 23 | body { 24 | display: grid; 25 | place-items: center; 26 | margin: 0; 27 | height: 100vh; 28 | padding: var(--space-m); 29 | font-size: var(--font-size); 30 | font-family: var(--font-family); 31 | line-height: 1.2; 32 | background-color: var(--color-tertiary); 33 | } 34 | 35 | a { 36 | color: var(--color-primary); 37 | } 38 | a:focus { 39 | color: var(--color-secondary); 40 | } 41 | 42 | h2 { 43 | font-weight: 700; 44 | font-size: calc(var(--font-size) * 1.5); 45 | } 46 | 47 | .form { 48 | position: relative; 49 | width: 100%; 50 | max-width: 450px; 51 | margin: 0 auto; 52 | -webkit-transform: skewY(-5deg) translateY(10%) scale(0.94); 53 | transform: skewY(-5deg) translateY(10%) scale(0.94); 54 | -webkit-transition: box-shadow var(--duration) var(--ease), -webkit-transform var(--duration) var(--ease); 55 | transition: box-shadow var(--duration) var(--ease), -webkit-transform var(--duration) var(--ease); 56 | transition: box-shadow var(--duration) var(--ease), transform var(--duration) var(--ease); 57 | transition: box-shadow var(--duration) var(--ease), transform var(--duration) var(--ease), -webkit-transform var(--duration) var(--ease); 58 | } 59 | .form:before, .form:after { 60 | content: ''; 61 | position: absolute; 62 | pointer-events: none; 63 | background-color: #ebebeb; 64 | width: 25%; 65 | height: 100%; 66 | -webkit-transition: background-color var(--duration) var(--ease), -webkit-transform var(--duration) var(--ease); 67 | transition: background-color var(--duration) var(--ease), -webkit-transform var(--duration) var(--ease); 68 | transition: background-color var(--duration) var(--ease), transform var(--duration) var(--ease); 69 | transition: background-color var(--duration) var(--ease), transform var(--duration) var(--ease), -webkit-transform var(--duration) var(--ease); 70 | } 71 | .form:before { 72 | top: 0; 73 | right: calc(100% - 1px); 74 | -webkit-transform-origin: 100% 100%; 75 | transform-origin: 100% 100%; 76 | -webkit-transform: skewY(-35deg) scaleX(-1); 77 | transform: skewY(-35deg) scaleX(-1); 78 | z-index: -1; 79 | } 80 | .form:after { 81 | top: 0; 82 | left: calc(100% - 1px); 83 | -webkit-transform-origin: 0 0; 84 | transform-origin: 0 0; 85 | -webkit-transform: skewY(-35deg) scaleX(-1); 86 | transform: skewY(-35deg) scaleX(-1); 87 | z-index: 2; 88 | } 89 | .form:hover, .form:focus-within { 90 | -webkit-transform: scale(1.0001); 91 | transform: scale(1.0001); 92 | box-shadow: 0 1rem 3rem rgba(0, 0, 0, 0.1); 93 | } 94 | .form:hover:before, .form:hover:after, .form:focus-within:before, .form:focus-within:after { 95 | background-color: white; 96 | -webkit-transform: skewY(0); 97 | transform: skewY(0); 98 | } 99 | 100 | .form-inner { 101 | padding: var(--space-xl); 102 | background-color: white; 103 | z-index: 1; 104 | } 105 | .form-inner > * + * { 106 | margin-top: var(--space-xl); 107 | } 108 | 109 | .input-wrapper:focus-within label { 110 | color: var(--color-secondary); 111 | } 112 | .input-wrapper:focus-within .icon { 113 | background-color: var(--color-secondary); 114 | } 115 | .input-wrapper:focus-within input { 116 | border-color: var(--color-secondary); 117 | } 118 | .input-wrapper + .input-wrapper { 119 | margin-top: var(--space-l); 120 | } 121 | 122 | .input-group { 123 | position: relative; 124 | } 125 | .input-group input { 126 | border-radius: var(--base-border-radius); 127 | } 128 | .input-group .icon { 129 | position: absolute; 130 | top: 0; 131 | left: 0; 132 | height: 100%; 133 | border-top-left-radius: var(--base-border-radius); 134 | border-bottom-left-radius: var(--base-border-radius); 135 | pointer-events: none; 136 | } 137 | 138 | label { 139 | font-size: calc(var(--font-size) / 1.65); 140 | font-weight: 700; 141 | text-transform: uppercase; 142 | letter-spacing: 0.065rem; 143 | display: block; 144 | margin-bottom: var(--space-xs); 145 | color: var(--color-primary); 146 | } 147 | 148 | .icon { 149 | display: -webkit-box; 150 | display: flex; 151 | -webkit-box-align: center; 152 | align-items: center; 153 | -webkit-box-flex: 0; 154 | flex: 0 1 auto; 155 | padding: var(--space-m); 156 | background-color: var(--color-primary); 157 | } 158 | .icon svg { 159 | width: 1.25em; 160 | height: 1.25em; 161 | fill: white; 162 | pointer-events: none; 163 | -webkit-user-select: none; 164 | -moz-user-select: none; 165 | -ms-user-select: none; 166 | user-select: none; 167 | -webkit-transition: -webkit-transform var(--duration) var(--ease); 168 | transition: -webkit-transform var(--duration) var(--ease); 169 | transition: transform var(--duration) var(--ease); 170 | transition: transform var(--duration) var(--ease), -webkit-transform var(--duration) var(--ease); 171 | } 172 | 173 | input { 174 | -webkit-box-flex: 1; 175 | flex: 1 1 0; 176 | width: 100%; 177 | outline: none; 178 | padding: var(--space-m); 179 | font-size: var(--font-size); 180 | font-family: var(--font-family); 181 | color: var(--color-secondary); 182 | border: 2px solid var(--color-primary); 183 | } 184 | input:focus { 185 | color: var(--color-primary); 186 | } 187 | 188 | .btn-group { 189 | display: -webkit-box; 190 | display: flex; 191 | -webkit-box-align: center; 192 | align-items: center; 193 | -webkit-box-pack: justify; 194 | justify-content: space-between; 195 | } 196 | .btn-group > * + * { 197 | margin-left: var(--space-s); 198 | } 199 | 200 | .btn { 201 | position: relative; 202 | overflow: hidden; 203 | display: -webkit-box; 204 | display: flex; 205 | -webkit-box-align: center; 206 | align-items: center; 207 | -webkit-box-pack: justify; 208 | justify-content: space-between; 209 | outline: none; 210 | padding: var(--space-m) var(--space-l); 211 | cursor: pointer; 212 | border: 2px solid transparent; 213 | border-radius: var(--base-border-radius); 214 | } 215 | 216 | .btn--primary { 217 | font-size: calc(var(--font-size) / 1.65); 218 | font-weight: 700; 219 | text-transform: uppercase; 220 | letter-spacing: 0.065rem; 221 | background-color: var(--color-primary); 222 | border-color: var(--color-primary); 223 | color: white; 224 | } 225 | .btn--primary:focus { 226 | background-color: var(--color-secondary); 227 | border-color: var(--color-secondary); 228 | } 229 | 230 | .btn--text { 231 | font-size: calc(var(--font-size) / 1.5); 232 | padding: 0; 233 | } -------------------------------------------------------------------------------- /src/controller/PublicManager.java: -------------------------------------------------------------------------------- 1 | package controller; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | import java.io.PrintWriter; 6 | import java.net.URLEncoder; 7 | import java.text.DateFormat; 8 | 9 | import javax.servlet.ServletException; 10 | import javax.servlet.annotation.MultipartConfig; 11 | import javax.servlet.http.HttpServlet; 12 | import javax.servlet.http.HttpServletRequest; 13 | import javax.servlet.http.HttpServletResponse; 14 | import javax.servlet.http.HttpSession; 15 | 16 | import exception.IdIsNullException; 17 | import service.UserService; 18 | import service.impl.UserServiceImpl; 19 | 20 | import java.util.ArrayList; 21 | import java.util.Date; 22 | 23 | import util.FileUtil; 24 | import util.OperUtil; 25 | 26 | @MultipartConfig //使用MultipartConfig注解标注改servlet能够接受文件上传的请求 27 | public class PublicManager extends HttpServlet { 28 | 29 | UserService userService = new UserServiceImpl(); 30 | 31 | public void doGet(HttpServletRequest req, HttpServletResponse res) 32 | throws ServletException, IOException { 33 | 34 | req.setCharacterEncoding("utf-8"); 35 | res.setContentType("text/html;charset=utf-8"); 36 | HttpSession session = req.getSession(); 37 | if(!session.isNew() && session.getAttribute("name") != null) { 38 | if(session.getAttribute("name").equals("admin")){ 39 | ; 40 | } else { 41 | res.sendRedirect("./Login"); 42 | return; 43 | } 44 | } else { 45 | res.sendRedirect("./Login"); 46 | return; 47 | } 48 | String method = (req.getParameter("method")!=null)?req.getParameter("method"):""; 49 | try { 50 | switch (method) { 51 | case "upload": 52 | uploadPage(req, res); 53 | break; 54 | case "create": 55 | case "delete": 56 | Page(req, res, method); 57 | break; 58 | default: 59 | mainPage(req, res); 60 | break; 61 | } 62 | } catch (Exception e) { 63 | e.printStackTrace(); 64 | } 65 | 66 | 67 | 68 | } 69 | 70 | private void uploadPage(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { 71 | 72 | HttpSession session = req.getSession(); 73 | String name = null; 74 | String sep = System.getProperty("file.separator"); 75 | String dir = null; 76 | if (req.getParameter("dir")==null || req.getParameter("dir").equals("")) { 77 | dir = sep; 78 | } else { 79 | dir = (String)req.getParameter("dir"); 80 | } 81 | 82 | 83 | 84 | String userpath = "." + sep + "publicshare" + dir; 85 | req.setAttribute("username", "admin"); 86 | req.setAttribute("path", dir); 87 | req.setAttribute("uploadpath", userpath); 88 | req.setAttribute("part", req.getPart("uploadfile")); 89 | req.getRequestDispatcher("/Upload").forward(req, res); 90 | 91 | 92 | 93 | 94 | } 95 | 96 | 97 | 98 | private void mainPage(HttpServletRequest req, HttpServletResponse res) 99 | throws ServletException, IOException { 100 | String name = null; 101 | String sep = System.getProperty("file.separator"); 102 | String dir = null; 103 | if (req.getParameter("dir")==null || req.getParameter("dir").equals("")) { 104 | dir = sep; 105 | } else { 106 | dir = (String)req.getParameter("dir"); 107 | } 108 | 109 | 110 | String userpath = "." + sep + "publicshare" + dir; 111 | 112 | ArrayList dirtotal = new ArrayList(); //存放用户目录下的目录信息列表 113 | ArrayList filetotal = new ArrayList(); //存放用户目录下的文件信息列表 114 | 115 | for (String i:FileUtil.getFiles(userpath)) { 116 | ArrayList info = new ArrayList(); 117 | File f = new File(i); 118 | String n = f.getName(); 119 | Double size = f.length()/1024.0; 120 | DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG,DateFormat.LONG); 121 | info.add(n); 122 | info.add(userService.getOwner(dir, n)); 123 | info.add(dateFormat.format(new Date(f.lastModified()))); 124 | if (size < 1024) { 125 | info.add(String.format("%.2fKB", size)); 126 | } else { 127 | info.add(String.format("%.2fMB", size/1024.0)); 128 | } 129 | info.add(FileUtil.ext(i)); 130 | filetotal.add(info); 131 | 132 | } 133 | 134 | 135 | for (String i:FileUtil.getDirs(userpath)) { 136 | ArrayList info = new ArrayList(); 137 | File f = new File(i); 138 | DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG,DateFormat.LONG); 139 | info.add(f.getName()); 140 | info.add(dateFormat.format(new Date(f.lastModified()))); 141 | info.add(String.valueOf(FileUtil.getTotalSizeOfFilesInDir(f)/1024)); 142 | info.add("DIR"); 143 | dirtotal.add(info); 144 | 145 | } 146 | 147 | req.setAttribute("filetotal", filetotal); 148 | req.setAttribute("dirtotal", dirtotal); 149 | req.setAttribute("dir", dir); 150 | req.setAttribute("name", name); 151 | req.getRequestDispatcher("/PublicManagerView").forward(req, res); 152 | } 153 | 154 | 155 | 156 | private void Page(HttpServletRequest req, HttpServletResponse res, String method) 157 | throws ServletException, IOException, IdIsNullException { 158 | String sep = System.getProperty("file.separator"); 159 | String dir = null; 160 | if (req.getParameter("dir")==null || req.getParameter("dir").equals("")) { 161 | dir = sep; 162 | } else { 163 | dir = (String)req.getParameter("dir"); 164 | } 165 | PrintWriter out = res.getWriter(); 166 | String filename = req.getParameter("name"); 167 | String path = dir; 168 | 169 | 170 | String userpath = "." + sep + "publicshare" + dir; 171 | 172 | switch (method) { 173 | case "create": 174 | 175 | if (OperUtil.create(userpath, filename)) { 176 | dir = URLEncoder.encode(dir, "UTF-8"); 177 | out.println(""); 179 | } else { 180 | dir = URLEncoder.encode(dir, "UTF-8"); 181 | out.println(""); 183 | } 184 | break; 185 | case "delete": 186 | if (req.getParameter("ifdir") != null) { 187 | userService.delShareDir(dir, filename); 188 | OperUtil.delete(new File(userpath+sep+filename)); 189 | dir = URLEncoder.encode(dir, "UTF-8"); 190 | out.println(""); 192 | 193 | } else { 194 | if (userService.deleteFile(dir, filename) > 0) { 195 | OperUtil.delete(new File(userpath+filename)); 196 | dir = URLEncoder.encode(dir, "UTF-8"); 197 | out.println(""); 199 | 200 | } else { 201 | dir = URLEncoder.encode(dir, "UTF-8"); 202 | out.println(""); 204 | } 205 | } 206 | 207 | break; 208 | 209 | } 210 | 211 | } 212 | 213 | 214 | 215 | public void doPost(HttpServletRequest req, HttpServletResponse res) 216 | throws ServletException, IOException { 217 | 218 | this.doGet(req, res); 219 | 220 | } 221 | 222 | } 223 | -------------------------------------------------------------------------------- /src/view/FindUserView.java: -------------------------------------------------------------------------------- 1 | package view; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | import java.io.PrintWriter; 6 | import java.net.URLEncoder; 7 | import java.util.List; 8 | import javax.servlet.ServletException; 9 | import javax.servlet.http.HttpServlet; 10 | import javax.servlet.http.HttpServletRequest; 11 | import javax.servlet.http.HttpServletResponse; 12 | 13 | import util.FileUtil; 14 | 15 | public class FindUserView extends HttpServlet { 16 | 17 | 18 | public void doGet(HttpServletRequest req, HttpServletResponse res) 19 | throws ServletException, IOException { 20 | req.setCharacterEncoding("utf-8"); 21 | res.setContentType("text/html;charset=utf-8"); 22 | PrintWriter out = res.getWriter(); 23 | List userli = (List)req.getAttribute("userli"); 24 | String sepp = System.getProperty("file.separator"); 25 | 26 | out.print("\r\n" + 27 | "\r\n" + 28 | "\r\n" + 29 | "\r\n" + 30 | "\r\n" + 31 | " \r\n" + 32 | " \r\n" + 33 | " \r\n" + 34 | " 千度网盘\r\n" + 35 | " \r\n" + 36 | " \r\n" + 37 | " \r\n" + 38 | " \r\n" + 39 | "\r\n" + 40 | "\r\n" + 41 | "\r\n" + 42 | "\r\n" + 43 | "
\r\n" + 44 | " \r\n" + 45 | "
\r\n" + 46 | " \r\n" + 66 | "
\r\n" + 67 | "
\r\n" + 68 | "
\r\n" + 69 | "
\r\n" + 70 | "
\r\n" + 71 | "
\r\n" + 72 | " \r\n" + 73 | "

Admin

\r\n" + 74 | " \r\n" + 75 | " \r\n" + 76 | " \r\n" + 77 | " \r\n" + 78 | " \r\n" + 79 | " \r\n" + 80 | "\r\n" + 81 | " \r\n" + 82 | "\r\n" + 83 | " \r\n" + 84 | "\r\n" + 85 | " \r\n" + 86 | "
空间占用等级
+∞ROOT
\r\n" + 87 | "
\r\n" + 88 | "
\r\n" + 89 | " \r\n" + 155 | "
\r\n" + 156 | "
\r\n" + 157 | "
\r\n" + 158 | "
\r\n" + 159 | " \r\n" + 160 | "\r\n " + 177 | "\r\n" + 178 | ""); 179 | 180 | 181 | 182 | 183 | } 184 | 185 | public void doPost(HttpServletRequest req, HttpServletResponse res) 186 | throws ServletException, IOException { 187 | 188 | this.doGet(req, res); 189 | } 190 | 191 | } 192 | -------------------------------------------------------------------------------- /src/view/AdminMain.java: -------------------------------------------------------------------------------- 1 | package view; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | import java.io.PrintWriter; 6 | import java.net.URLEncoder; 7 | import java.util.List; 8 | 9 | import javax.servlet.ServletException; 10 | import javax.servlet.http.HttpServlet; 11 | import javax.servlet.http.HttpServletRequest; 12 | import javax.servlet.http.HttpServletResponse; 13 | import javax.servlet.http.HttpSession; 14 | 15 | import service.UserService; 16 | import service.impl.UserServiceImpl; 17 | import util.FileUtil; 18 | 19 | public class AdminMain extends HttpServlet { 20 | 21 | UserService userservice = new UserServiceImpl(); 22 | 23 | public void doGet(HttpServletRequest req, HttpServletResponse res) 24 | throws ServletException, IOException { 25 | req.setCharacterEncoding("utf-8"); 26 | res.setContentType("text/html;charset=utf-8"); 27 | PrintWriter out = res.getWriter(); 28 | HttpSession session = req.getSession(); 29 | String del = req.getParameter("del"); 30 | String sepp = System.getProperty("file.separator"); 31 | 32 | if (del != null) { 33 | 34 | session.invalidate(); 35 | res.sendRedirect("./AdminLogin"); 36 | 37 | } else { 38 | 39 | if(!session.isNew()){ 40 | if(session.getAttribute("admin") != null){ 41 | res.sendRedirect("./AdminLoginController"); 42 | } 43 | } 44 | 45 | 46 | } 47 | List userli = userservice.selectAll(); 48 | out.print("\r\n" + 49 | "\r\n" + 50 | "\r\n" + 51 | "\r\n" + 52 | "\r\n" + 53 | " \r\n" + 54 | " \r\n" + 55 | " \r\n" + 56 | " 千度网盘\r\n" + 57 | " \r\n" + 58 | " \r\n" + 59 | " \r\n" + 60 | " \r\n" + 61 | "\r\n" + 62 | "\r\n" + 63 | "\r\n" + 64 | "\r\n" + 65 | "
\r\n" + 66 | " \r\n" + 67 | "
\r\n" + 68 | " \r\n" + 88 | "
\r\n" + 89 | "
\r\n" + 90 | "
\r\n" + 91 | "
\r\n" + 92 | "
\r\n" + 93 | "
\r\n" + 94 | " \r\n" + 95 | "

Admin

\r\n" + 96 | " \r\n" + 97 | " \r\n" + 98 | " \r\n" + 99 | " \r\n" + 100 | " \r\n" + 101 | " \r\n" + 102 | "\r\n" + 103 | " \r\n" + 104 | "\r\n" + 105 | " \r\n" + 106 | "\r\n" + 107 | " \r\n" + 108 | "
空间占用等级
+∞ROOT
\r\n" + 109 | "
\r\n" + 110 | "
\r\n" + 111 | " \r\n" + 177 | "
\r\n" + 178 | "
\r\n" + 179 | "
\r\n" + 180 | "
\r\n" + 181 | " \r\n" + 182 | "\r\n " + 199 | "\r\n" + 200 | ""); 201 | 202 | 203 | 204 | 205 | } 206 | 207 | public void doPost(HttpServletRequest req, HttpServletResponse res) 208 | throws ServletException, IOException { 209 | 210 | this.doGet(req, res); 211 | } 212 | 213 | } 214 | -------------------------------------------------------------------------------- /src/view/FindFileAdminView.java: -------------------------------------------------------------------------------- 1 | package view; 2 | 3 | import java.io.IOException; 4 | import java.io.PrintWriter; 5 | import java.net.URLEncoder; 6 | import java.util.ArrayList; 7 | import javax.servlet.ServletException; 8 | import javax.servlet.http.HttpServlet; 9 | import javax.servlet.http.HttpServletRequest; 10 | import javax.servlet.http.HttpServletResponse; 11 | 12 | public class FindFileAdminView extends HttpServlet { 13 | 14 | public void doGet(HttpServletRequest req, HttpServletResponse res) 15 | throws ServletException, IOException { 16 | req.setCharacterEncoding("utf-8"); 17 | res.setContentType("text/html;charset=utf-8"); 18 | PrintWriter out = res.getWriter(); 19 | ArrayList filetotal = (ArrayList) req.getAttribute("filetotal"); 20 | 21 | 22 | out.print("\r\n" + 23 | "\r\n" + 24 | "\r\n" + 25 | "\r\n" + 26 | "\r\n" + 27 | " \r\n" + 28 | " \r\n" + 29 | " \r\n" + 30 | " 千度网盘\r\n" + 31 | " \r\n" + 32 | " \r\n" + 33 | " \r\n" + 34 | " \r\n" + 35 | " \r\n" + 47 | "\r\n" + 48 | "\r\n" + 49 | "\r\n" + 50 | "\r\n" + 51 | "
\r\n" + 52 | " \r\n" + 53 | "
\r\n" + 54 | " \r\n" + 74 | "
\r\n" + 75 | "
\r\n" + 76 | "
\r\n" + 77 | "
\r\n" + 78 | "
\r\n" + 79 | "
\r\n" + 80 | " \r\n" + 81 | "

Admin

\r\n" + 82 | " \r\n" + 83 | " \r\n" + 84 | " \r\n" + 85 | " \r\n" + 86 | " \r\n" + 87 | " \r\n" + 88 | "\r\n" + 89 | " \r\n" + 90 | "\r\n" + 91 | " \r\n" + 92 | "\r\n" + 93 | " \r\n" + 94 | "
空间占用等级
+∞ROOT
\r\n" + 95 | "
\r\n" + 96 | "
\r\n" + 97 | "
\r\n" + 98 | "\r\n" + 99 | "
\r\n" + 100 | "
\r\n" + 101 | "

公共分享

\r\n" + 102 | "
\r\n" + 103 | "
\r\n" + 104 | " " + 105 | " \r\n" + 106 | "
\r\n" + 107 | " \r\n" + 108 | "\r\n" + 109 | "
"); 110 | 111 | 112 | out.print("公共资源管理>> \r\n"); 113 | 114 | 115 | 116 | 117 | out.print("\r\n" + 118 | " \r\n" + 119 | " \r\n" + 120 | " \r\n" + 121 | " \r\n" + 122 | " \r\n" + 123 | " \r\n" + 124 | " \r\n" + 125 | " \r\n" + 126 | " \r\n" + 127 | " "); 128 | if (filetotal != null) { 129 | 130 | 131 | for (ArrayList fli : filetotal) { 132 | String si = null; 133 | Double size = Long.valueOf((String)fli.get(3))/1024.0; 134 | if (size < 1024) { 135 | si = (String.format("%.2fKB", size)); 136 | } else { 137 | si = (String.format("%.2fMB", size/1024.0)); 138 | } 139 | out.print("\r\n" + 140 | " \r\n" + 141 | " \r\n" + 142 | " \r\n" + 143 | " \r\n" + 144 | " \r\n" + 145 | " \r\n" + 146 | " \r\n" + 147 | " \r\n" + 148 | " \r\n" + 149 | " "); 150 | 151 | 152 | 153 | } 154 | 155 | 156 | 157 | } else { 158 | out.print("\r\n" + 159 | " \r\n" + 160 | " "); 161 | } 162 | 163 | 164 | 165 | 166 | out.print("
文件名上传者资源路径大小上传日期类型操作
"+fli.get(0)+""+fli.get(1)+""+fli.get(2)+""+fli.get(3)+""+fli.get(4)+""+fli.get(5)+"删除下载
对不起,没有找到文件了
\r\n" + 167 | "
\r\n" + 168 | "
\r\n" + 169 | "
\r\n" + 170 | "
\r\n" + 171 | "
\r\n" + 172 | "
\r\n" + 173 | " \r\n" + 174 | "\r\n" + 175 | " \r\n" + 191 | "\r\n" + 192 | ""); 193 | 194 | 195 | 196 | 197 | } 198 | 199 | public void doPost(HttpServletRequest req, HttpServletResponse res) 200 | throws ServletException, IOException { 201 | 202 | this.doGet(req, res); 203 | } 204 | 205 | } 206 | 207 | -------------------------------------------------------------------------------- /src/controller/UserFile.java: -------------------------------------------------------------------------------- 1 | package controller; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | import java.io.PrintWriter; 6 | import java.net.URLEncoder; 7 | import java.text.DateFormat; 8 | import java.util.ArrayList; 9 | import java.util.Date; 10 | 11 | import javax.servlet.ServletException; 12 | import javax.servlet.annotation.MultipartConfig; 13 | import javax.servlet.http.Cookie; 14 | import javax.servlet.http.HttpServlet; 15 | import javax.servlet.http.HttpServletRequest; 16 | import javax.servlet.http.HttpServletResponse; 17 | import javax.servlet.http.HttpSession; 18 | 19 | import service.UserService; 20 | import service.impl.UserServiceImpl; 21 | import util.FileUtil; 22 | import util.OperUtil; 23 | 24 | @MultipartConfig //使用MultipartConfig注解标注改servlet能够接受文件上传的请求 25 | public class UserFile extends HttpServlet { 26 | 27 | UserService userService = new UserServiceImpl(); 28 | 29 | public void doGet(HttpServletRequest req, HttpServletResponse res) 30 | throws ServletException, IOException { 31 | req.setCharacterEncoding("utf-8"); 32 | res.setContentType("text/html;charset=utf-8"); 33 | HttpSession session = req.getSession(); 34 | String name = req.getParameter("username"); 35 | String method = (req.getParameter("method")!=null)?req.getParameter("method"):""; 36 | 37 | if(!session.isNew() && session.getAttribute("name") != null) { 38 | if(session.getAttribute("name").equals("admin")){ 39 | ; 40 | } else { 41 | res.sendRedirect("./Login"); 42 | return; 43 | } 44 | } else { 45 | res.sendRedirect("./Login"); 46 | return; 47 | } 48 | 49 | switch (method) { 50 | case "upload": 51 | uploadPage(req, res); 52 | break; 53 | case "create": 54 | case "delete": 55 | case "share": 56 | Page(req, res, method); 57 | break; 58 | default: 59 | mainPage(req, res); 60 | break; 61 | 62 | } 63 | 64 | 65 | 66 | 67 | 68 | } 69 | 70 | private void uploadPage(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { 71 | 72 | 73 | String name = req.getParameter("username"); 74 | String sep = System.getProperty("file.separator"); 75 | String dir = null; 76 | if (req.getParameter("dir")==null || req.getParameter("dir").equals("")) { 77 | dir = sep; 78 | } else { 79 | dir = (String)req.getParameter("dir"); 80 | } 81 | 82 | String userpath = "." + sep + "userfile" + sep + name + "qiandu" + dir; 83 | req.setAttribute("path", dir); 84 | req.setAttribute("ownname", name); 85 | req.setAttribute("uploadpath", userpath); 86 | req.setAttribute("part", req.getPart("uploadfile")); 87 | req.getRequestDispatcher("/Upload").forward(req, res); 88 | 89 | 90 | 91 | 92 | } 93 | 94 | private void mainPage(HttpServletRequest req, HttpServletResponse res) 95 | throws ServletException, IOException { 96 | 97 | String sep = System.getProperty("file.separator"); 98 | String dir = null; 99 | if (req.getParameter("dir")==null || req.getParameter("dir").equals("")) { 100 | dir = sep; 101 | } else { 102 | dir = (String)req.getParameter("dir"); 103 | } 104 | String name = req.getParameter("username"); 105 | if (name.equals("admin")) { 106 | res.sendRedirect("./AdminHome"); 107 | return; 108 | } 109 | 110 | String userpath = "." + sep + "userfile" + sep + name + "qiandu" + dir; 111 | 112 | ArrayList dirtotal = new ArrayList(); //存放用户目录下的目录信息列表 113 | ArrayList filetotal = new ArrayList(); //存放用户目录下的文件信息列表 114 | 115 | for (String i:FileUtil.getFiles(userpath)) { 116 | ArrayList info = new ArrayList(); 117 | File f = new File(i); 118 | Double size = f.length()/1024.0; 119 | DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG,DateFormat.LONG); 120 | info.add(f.getName()); 121 | info.add(dateFormat.format(new Date(f.lastModified()))); 122 | if (size < 1024) { 123 | info.add(String.format("%.2fKB", size)); 124 | } else { 125 | info.add(String.format("%.2fMB", size/1024.0)); 126 | } 127 | info.add(FileUtil.ext(i)); 128 | filetotal.add(info); 129 | 130 | } 131 | 132 | 133 | for (String i:FileUtil.getDirs(userpath)) { 134 | ArrayList info = new ArrayList(); 135 | File f = new File(i); 136 | Double size = FileUtil.getTotalSizeOfFilesInDir(f)/1024.0; 137 | DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG,DateFormat.LONG); 138 | info.add(f.getName()); 139 | info.add(dateFormat.format(new Date(f.lastModified()))); 140 | if (size < 1024) { 141 | info.add(String.format("%.2fKB", size)); 142 | } else { 143 | info.add(String.format("%.2fMB", size/1024.0)); 144 | } 145 | info.add("DIR"); 146 | dirtotal.add(info); 147 | 148 | } 149 | 150 | req.setAttribute("filetotal", filetotal); 151 | req.setAttribute("dirtotal", dirtotal); 152 | req.setAttribute("dir", dir); 153 | req.setAttribute("name", name); 154 | req.getRequestDispatcher("/UserFileView").forward(req, res); 155 | } 156 | 157 | private void Page(HttpServletRequest req, HttpServletResponse res, String method) 158 | throws ServletException, IOException { 159 | String sep = System.getProperty("file.separator"); 160 | String dir = null; 161 | if (req.getParameter("dir")==null || req.getParameter("dir").equals("")) { 162 | dir = sep; 163 | } else { 164 | dir = (String)req.getParameter("dir"); 165 | } 166 | String name = req.getParameter("username"); 167 | PrintWriter out = res.getWriter(); 168 | 169 | 170 | 171 | String userpath = "." + sep + "userfile" + sep + name + "qiandu" + dir; 172 | 173 | switch (method) { 174 | case "create": 175 | 176 | if (userService.insertHome(name, dir, req.getParameter("name"), -1, new Date(), "DIR")>0 && OperUtil.create(userpath, req.getParameter("name"))) { 177 | dir = URLEncoder.encode(dir, "UTF-8"); 178 | out.println(""); 180 | } else { 181 | dir = URLEncoder.encode(dir, "UTF-8"); 182 | out.println(""); 184 | } 185 | break; 186 | case "delete": 187 | 188 | if (userService.deleteHome(name, dir, req.getParameter("name"))>0) { 189 | OperUtil.delete(new File(userpath+req.getParameter("name"))); 190 | dir = URLEncoder.encode(dir, "UTF-8"); 191 | out.println(""); 193 | 194 | } else { 195 | 196 | dir = URLEncoder.encode(dir, "UTF-8"); 197 | out.println(""); 199 | } 200 | break; 201 | 202 | case "share": 203 | File f = new File(userpath+sep+req.getParameter("name")); 204 | long size = f.length(); 205 | String ext = FileUtil.ext(req.getParameter("name")); 206 | 207 | if (userService.insertFile(name, sep, req.getParameter("name"), size, new Date(), ext)>0 && OperUtil.share(userpath, req.getParameter("name"), "." + sep + "publicshare" + sep)) { 208 | dir = URLEncoder.encode(dir, "UTF-8"); 209 | out.println(""); 211 | } else { 212 | dir = URLEncoder.encode(dir, "UTF-8"); 213 | out.println(""); 215 | } 216 | break; 217 | } 218 | 219 | } 220 | 221 | 222 | public void doPost(HttpServletRequest req, HttpServletResponse res) 223 | throws ServletException, IOException { 224 | 225 | this.doGet(req, res); 226 | 227 | } 228 | } 229 | -------------------------------------------------------------------------------- /WebContent/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | CharacterEncodingFilter 5 | filter.CharacterEncodingFilter 6 | 7 | encode 8 | utf-8 9 | 10 | 11 | 12 | 13 | FirstServlet 14 | startup.FirstServlet 15 | 1 16 | 17 | 18 | LoginController 19 | controller.LoginController 20 | 21 | 22 | Login 23 | view.Login 24 | 25 | 26 | Home 27 | controller.Home 28 | 29 | 30 | Main 31 | view.Main 32 | 33 | 34 | Register 35 | view.Register 36 | 37 | 38 | MyShareView 39 | view.MyShareView 40 | 41 | 42 | RegisterController 43 | controller.RegisterController 44 | 45 | 46 | Upload 47 | controller.Upload 48 | 49 | 50 | MyShare 51 | controller.MyShare 52 | 53 | 54 | PublicShare 55 | controller.PublicShare 56 | 57 | 58 | PublicShareView 59 | view.PublicShareView 60 | 61 | 62 | DownloadFile 63 | util.DownloadFile 64 | 65 | 66 | FindFile 67 | controller.FindFile 68 | 69 | 70 | FindFileView 71 | view.FindFileView 72 | 73 | 74 | AdminHome 75 | controller.AdminHome 76 | 77 | 78 | AdminMain 79 | view.AdminMain 80 | 81 | 82 | UserFile 83 | controller.UserFile 84 | 85 | 86 | UserFileView 87 | view.UserFileView 88 | 89 | 90 | PublicManagerView 91 | view.PublicManagerView 92 | 93 | 94 | PublicManager 95 | controller.PublicManager 96 | 97 | 98 | FindUser 99 | controller.FindUser 100 | 101 | 102 | FindUserView 103 | view.FindUserView 104 | 105 | 106 | FindFileAdminView 107 | view.FindFileAdminView 108 | 109 | 110 | FindFileAdmin 111 | controller.FindFileAdmin 112 | 113 | 114 | FindAnyView 115 | view.FindAnyView 116 | 117 | 118 | 119 | 120 | LoginController 121 | /LoginController 122 | 123 | 124 | Login 125 | /Login 126 | 127 | 128 | Home 129 | /Home 130 | 131 | 132 | Main 133 | /Main 134 | 135 | 136 | Register 137 | /Register 138 | 139 | 140 | RegisterController 141 | /RegisterController 142 | 143 | 144 | Upload 145 | /Upload 146 | 147 | 148 | MyShare 149 | /MyShare 150 | 151 | 152 | MyShareView 153 | /MyShareView 154 | 155 | 156 | PublicShareView 157 | /PublicShareView 158 | 159 | 160 | PublicShare 161 | /PublicShare 162 | 163 | 164 | DownloadFile 165 | /DownloadFile 166 | 167 | 168 | FindFile 169 | /FindFile 170 | 171 | 172 | FindFileView 173 | /FindFileView 174 | 175 | 176 | AdminHome 177 | /AdminHome 178 | 179 | 180 | AdminMain 181 | /AdminMain 182 | 183 | 184 | UserFile 185 | /UserFile 186 | 187 | 188 | UserFileView 189 | /UserFileView 190 | 191 | 192 | PublicManagerView 193 | /PublicManagerView 194 | 195 | 196 | PublicManager 197 | /PublicManager 198 | 199 | 200 | FindUser 201 | /FindUser 202 | 203 | 204 | FindUserView 205 | /FindUserView 206 | 207 | 208 | FindFileAdminView 209 | /FindFileAdminView 210 | 211 | 212 | FindFileAdmin 213 | /FindFileAdmin 214 | 215 | 216 | FindAnyView 217 | /FindAnyView 218 | 219 | 220 | 221 | 222 | Login 223 | 224 | -------------------------------------------------------------------------------- /src/controller/Home.java: -------------------------------------------------------------------------------- 1 | package controller; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | import java.io.PrintWriter; 6 | import java.net.URLEncoder; 7 | import java.text.DateFormat; 8 | 9 | import javax.servlet.ServletException; 10 | import javax.servlet.annotation.MultipartConfig; 11 | import javax.servlet.http.HttpServlet; 12 | import javax.servlet.http.HttpServletRequest; 13 | import javax.servlet.http.HttpServletResponse; 14 | import javax.servlet.http.HttpSession; 15 | 16 | import service.UserService; 17 | import service.impl.UserServiceImpl; 18 | 19 | import java.util.ArrayList; 20 | import java.util.Date; 21 | 22 | import util.FileUtil; 23 | import util.OperUtil; 24 | 25 | @MultipartConfig //使用MultipartConfig注解标注改servlet能够接受文件上传的请求 26 | public class Home extends HttpServlet { 27 | 28 | UserService userService = new UserServiceImpl(); 29 | 30 | public void doGet(HttpServletRequest req, HttpServletResponse res) 31 | throws ServletException, IOException { 32 | 33 | req.setCharacterEncoding("utf-8"); 34 | res.setContentType("text/html;charset=utf-8"); 35 | HttpSession session = req.getSession(); 36 | String method = (req.getParameter("method")!=null)?req.getParameter("method"):""; 37 | if(!session.isNew() && session.getAttribute("name") != null){ 38 | if (session.getAttribute("name").equals("admin")) { 39 | req.getRequestDispatcher("/AdminHome").forward(req, res); 40 | } 41 | } 42 | switch (method) { 43 | case "upload": 44 | uploadPage(req, res); 45 | break; 46 | case "create": 47 | case "delete": 48 | case "rename": 49 | case "share": 50 | Page(req, res, method); 51 | break; 52 | default: 53 | mainPage(req, res); 54 | break; 55 | 56 | } 57 | 58 | } 59 | 60 | private void uploadPage(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { 61 | 62 | HttpSession session = req.getSession(); 63 | String sep = System.getProperty("file.separator"); 64 | String dir = null; 65 | if (req.getParameter("dir")==null || req.getParameter("dir").equals("")) { 66 | dir = sep; 67 | } else { 68 | dir = (String)req.getParameter("dir"); 69 | } 70 | String name = null; 71 | 72 | if(!session.isNew() && session.getAttribute("name") != null){ 73 | name = (String)session.getAttribute("name"); 74 | } else { 75 | res.sendRedirect("./Login"); 76 | return; 77 | } 78 | String userpath = "." + sep + "userfile" + sep + name + "qiandu" + dir; 79 | req.setAttribute("path", dir); 80 | req.setAttribute("ownname", name); 81 | req.setAttribute("uploadpath", userpath); 82 | req.setAttribute("part", req.getPart("uploadfile")); 83 | req.getRequestDispatcher("/Upload").forward(req, res); 84 | 85 | 86 | 87 | 88 | } 89 | 90 | 91 | 92 | private void mainPage(HttpServletRequest req, HttpServletResponse res) 93 | throws ServletException, IOException { 94 | HttpSession session = req.getSession(); 95 | String sep = System.getProperty("file.separator"); 96 | String dir = null; 97 | if (req.getParameter("dir")==null || req.getParameter("dir").equals("")) { 98 | dir = sep; 99 | } else { 100 | dir = (String)req.getParameter("dir"); 101 | } 102 | String name = null; 103 | if(!session.isNew() && session.getAttribute("name") != null){ 104 | name = (String)session.getAttribute("name"); 105 | } else { 106 | res.sendRedirect("./Login"); 107 | return; 108 | } 109 | 110 | String userpath = "." + sep + "userfile" + sep + name + "qiandu" + dir; 111 | 112 | 113 | ArrayList dirtotal = new ArrayList(); //存放用户目录下的目录信息列表 114 | ArrayList filetotal = new ArrayList(); //存放用户目录下的文件信息列表 115 | 116 | for (String i:FileUtil.getFiles(userpath)) { 117 | ArrayList info = new ArrayList(); 118 | File f = new File(i); 119 | Double size = f.length()/1024.0; 120 | DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG,DateFormat.LONG); 121 | info.add(f.getName()); 122 | info.add(dateFormat.format(new Date(f.lastModified()))); 123 | if (size < 1024) { 124 | info.add(String.format("%.2fKB", size)); 125 | } else { 126 | info.add(String.format("%.2fMB", size/1024.0)); 127 | } 128 | info.add(FileUtil.ext(i)); 129 | filetotal.add(info); 130 | 131 | } 132 | 133 | 134 | for (String i:FileUtil.getDirs(userpath)) { 135 | ArrayList info = new ArrayList(); 136 | File f = new File(i); 137 | Double size = FileUtil.getTotalSizeOfFilesInDir(f)/1024.0; 138 | DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG,DateFormat.LONG); 139 | info.add(f.getName()); 140 | info.add(dateFormat.format(new Date(f.lastModified()))); 141 | if (size < 1024) { 142 | info.add(String.format("%.2fKB", size)); 143 | } else { 144 | info.add(String.format("%.2fMB", size/1024.0)); 145 | } 146 | info.add("DIR"); 147 | dirtotal.add(info); 148 | 149 | } 150 | 151 | req.setAttribute("filetotal", filetotal); 152 | req.setAttribute("dirtotal", dirtotal); 153 | req.setAttribute("dir", dir); 154 | req.setAttribute("name", name); 155 | req.getRequestDispatcher("/Main").forward(req, res); 156 | } 157 | 158 | 159 | 160 | private void Page(HttpServletRequest req, HttpServletResponse res, String method) 161 | throws ServletException, IOException { 162 | HttpSession session = req.getSession(); 163 | String sep = System.getProperty("file.separator"); 164 | String dir = null; 165 | if (req.getParameter("dir")==null || req.getParameter("dir").equals("")) { 166 | dir = sep; 167 | } else { 168 | dir = (String)req.getParameter("dir"); 169 | } 170 | String name = null; 171 | PrintWriter out = res.getWriter(); 172 | 173 | if(!session.isNew() && session.getAttribute("name") != null){ 174 | name = (String)session.getAttribute("name"); 175 | } else { 176 | res.sendRedirect("./Login"); 177 | return; 178 | } 179 | 180 | String userpath = "." + sep + "userfile" + sep + name + "qiandu" + dir; 181 | 182 | 183 | switch (method) { 184 | case "create": 185 | if (userService.insertHome(name, dir, req.getParameter("name"), -1, new Date(), "DIR")>0 && OperUtil.create(userpath, req.getParameter("name"))) { 186 | dir = URLEncoder.encode(dir, "UTF-8"); 187 | out.println(""); 189 | } else { 190 | dir = URLEncoder.encode(dir, "UTF-8"); 191 | out.println(""); 193 | } 194 | break; 195 | case "delete": 196 | if (userService.deleteHome(name, dir, req.getParameter("name"))>0) { 197 | OperUtil.delete(new File(userpath+req.getParameter("name"))); 198 | dir = URLEncoder.encode(dir, "UTF-8"); 199 | out.println(""); 201 | 202 | } else { 203 | dir = URLEncoder.encode(dir, "UTF-8"); 204 | out.println(""); 206 | } 207 | break; 208 | case "share": 209 | File f = new File(userpath+req.getParameter("name")); 210 | long size = f.length(); 211 | String ext = FileUtil.ext(req.getParameter("name")); 212 | 213 | if (userService.insertFile(name, sep, req.getParameter("name"), size, new Date(), ext)>0 && OperUtil.share(userpath, req.getParameter("name"), "." + sep + "publicshare" + sep)) { 214 | dir = URLEncoder.encode(dir, "UTF-8"); 215 | out.println(""); 217 | } else { 218 | dir = URLEncoder.encode(dir, "UTF-8"); 219 | out.println(""); 221 | } 222 | break; 223 | } 224 | 225 | } 226 | 227 | 228 | 229 | public void doPost(HttpServletRequest req, HttpServletResponse res) 230 | throws ServletException, IOException { 231 | 232 | this.doGet(req, res); 233 | 234 | } 235 | 236 | } 237 | -------------------------------------------------------------------------------- /src/view/MyShareView.java: -------------------------------------------------------------------------------- 1 | package view; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | import java.io.PrintWriter; 6 | import java.net.URLEncoder; 7 | import java.util.ArrayList; 8 | import javax.servlet.ServletException; 9 | import javax.servlet.http.HttpServlet; 10 | import javax.servlet.http.HttpServletRequest; 11 | import javax.servlet.http.HttpServletResponse; 12 | 13 | import util.FileUtil; 14 | 15 | public class MyShareView extends HttpServlet { 16 | 17 | public void doGet(HttpServletRequest req, HttpServletResponse res) 18 | throws ServletException, IOException { 19 | req.setCharacterEncoding("utf-8"); 20 | res.setContentType("text/html;charset=utf-8"); 21 | PrintWriter out = res.getWriter(); 22 | String sepp = System.getProperty("file.separator"); 23 | 24 | String name = (String) req.getAttribute("name"); 25 | String dir = null; 26 | ArrayList mysharetotal = (ArrayList) req.getAttribute("mysharetotal"); 27 | 28 | if (req.getParameter("dir")==null || req.getParameter("dir").equals("")) { 29 | dir = sepp; 30 | } else { 31 | dir = (String)req.getParameter("dir"); 32 | } 33 | 34 | String userpath = "." + sepp + "userfile" + sepp + name + "qiandu"; 35 | Double size = FileUtil.getTotalSizeOfFilesInDir(new File(userpath))/1024.0; 36 | String si = null; 37 | if (size < 1024) { 38 | si = String.format("%.2fKB", size); 39 | } else { 40 | si = String.format("%.2fMB", size/1024.0); 41 | } 42 | 43 | out.print("\r\n" + 44 | "\r\n" + 45 | "\r\n" + 46 | "\r\n" + 47 | "\r\n" + 48 | " \r\n" + 49 | " \r\n" + 50 | " \r\n" + 51 | " 千度网盘\r\n" + 52 | " \r\n" + 53 | " \r\n" + 54 | " \r\n" + 55 | " \r\n" + 56 | " \r\n" + 57 | "\r\n" + 58 | "\r\n" + 59 | "\r\n" + 60 | "\r\n" + 61 | "
\r\n" + 62 | " \r\n" + 63 | "
\r\n" + 64 | " \r\n" + 87 | "
\r\n" + 88 | "
\r\n" + 89 | "
\r\n" + 90 | "
\r\n" + 91 | "
\r\n" + 92 | "
\r\n" + 93 | " \r\n" + 94 | "

"+name+"

\r\n" + 95 | " \r\n" + 96 | " \r\n" + 97 | " \r\n" + 98 | " \r\n" + 99 | " \r\n" + 100 | " \r\n" + 101 | "\r\n" + 102 | " \r\n" + 103 | "\r\n" + 104 | " \r\n" + 105 | "\r\n" + 106 | " \r\n" + 107 | "
空间占用等级
"+si+"普通用户
\r\n" + 108 | "
\r\n" + 109 | "
\r\n" + 110 | "
\r\n" + 111 | "\r\n" + 112 | "
\r\n" + 113 | "
\r\n" + 114 | "

我的分享

\r\n" + 115 | "\r\n" + 116 | "
\r\n" + 117 | "
\r\n" + 118 | " \r\n" + 119 | " \r\n" + 120 | "
\r\n" + 121 | " \r\n" + 122 | "\r\n" + 123 | "
\r\n" + 124 | "\r\n" + 125 | " 我的分享>>\r\n" + 126 | "\r\n" + 127 | "\r\n" + 128 | " \r\n" + 129 | " \r\n" + 130 | " \r\n" + 131 | " \r\n" + 132 | " \r\n" + 133 | " \r\n" + 134 | " \r\n" + 135 | " \r\n" + 136 | " \r\n" + 137 | " "); 138 | 139 | 140 | if (!(mysharetotal.isEmpty())) { 141 | for (ArrayList fli : mysharetotal) { 142 | out.print("\r\n" + 143 | " \r\n" + 144 | " \r\n" + 145 | " \r\n" + 146 | " \r\n" + 147 | " \r\n" + 148 | " \r\n" + 149 | " \r\n" + 151 | " \r\n" + 152 | " "); 153 | 154 | } 155 | 156 | 157 | 158 | } else { 159 | out.print("\r\n" + 160 | " \r\n" + 161 | " "); 162 | } 163 | 164 | out.print("
文件名共享路径上传日期大小类型操作
"+fli.get(0)+""+fli.get(1)+""+fli.get(2)+""+fli.get(3)+""+fli.get(4)+"删除 下载
对不起,没有文件了
\r\n" + 165 | "
\r\n" + 166 | "
\r\n" + 167 | "
\r\n" + 168 | "
\r\n" + 169 | "
\r\n" + 170 | "
\r\n" + 171 | " \r\n" + 172 | "\r\n" + 173 | "\r\n" + 174 | ""); 175 | 176 | 177 | 178 | 179 | } 180 | 181 | public void doPost(HttpServletRequest req, HttpServletResponse res) 182 | throws ServletException, IOException { 183 | 184 | this.doGet(req, res); 185 | } 186 | 187 | } 188 | 189 | -------------------------------------------------------------------------------- /src/view/FindAnyView.java: -------------------------------------------------------------------------------- 1 | package view; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | import java.io.PrintWriter; 6 | import java.net.URLEncoder; 7 | import java.util.ArrayList; 8 | import javax.servlet.ServletException; 9 | import javax.servlet.http.HttpServlet; 10 | import javax.servlet.http.HttpServletRequest; 11 | import javax.servlet.http.HttpServletResponse; 12 | 13 | import util.FileUtil; 14 | 15 | 16 | public class FindAnyView extends HttpServlet { 17 | 18 | public void doGet(HttpServletRequest req, HttpServletResponse res) 19 | throws ServletException, IOException { 20 | req.setCharacterEncoding("utf-8"); 21 | res.setContentType("text/html;charset=utf-8"); 22 | PrintWriter out = res.getWriter(); 23 | String sepp = System.getProperty("file.separator"); 24 | 25 | String name = (String) req.getAttribute("name"); 26 | String dir = (String) req.getAttribute("dir"); 27 | ArrayList filetotal = ((ArrayList) req.getAttribute("filetotal"))!=null?((ArrayList) req.getAttribute("filetotal")):new ArrayList(); 28 | 29 | if (dir == null || dir.equals("")) { 30 | dir = sepp; 31 | } 32 | 33 | out.print("\r\n" + 34 | "\r\n" + 35 | "\r\n" + 36 | "\r\n" + 37 | "\r\n" + 38 | " \r\n" + 39 | " \r\n" + 40 | " \r\n" + 41 | " 千度网盘\r\n" + 42 | " \r\n" + 43 | " \r\n" + 44 | " \r\n" + 45 | " \r\n" + 46 | " \r\n" + 58 | "\r\n" + 59 | "\r\n" + 60 | "\r\n" + 61 | "\r\n" + 62 | "
\r\n" + 63 | " \r\n" + 64 | "
\r\n" + 65 | " \r\n" + 86 | "
\r\n" + 87 | "
\r\n" + 88 | "
\r\n" + 89 | "
\r\n" + 90 | "
\r\n" + 91 | "
\r\n" + 92 | " \r\n" + 93 | "

Admin

\r\n" + 94 | " \r\n" + 95 | " \r\n" + 96 | " \r\n" + 97 | " \r\n" + 98 | " \r\n" + 99 | " \r\n" + 100 | "\r\n" + 101 | " \r\n" + 102 | "\r\n" + 103 | " \r\n" + 104 | "\r\n" + 105 | " \r\n" + 106 | "
空间占用等级
+∞ROOT
\r\n" + 107 | "
\r\n" + 108 | "
\r\n" + 109 | "
\r\n" + 110 | "\r\n" + 111 | "
\r\n" + 112 | "
\r\n" + 113 | "

用户及资源管理

\r\n" + 114 | "
\r\n" + 115 | "
\r\n" + 116 | " \r\n" + 117 | " \r\n" + 118 | "
\r\n" + 119 | " \r\n" + 120 | "\r\n" + 121 | "
"); 122 | 123 | 124 | out.print("所有用户>> \r\n"); 125 | out.print(""+name+">> \r\n"); 126 | 127 | 128 | out.print("\r\n" + 129 | " \r\n" + 130 | " \r\n" + 131 | " \r\n" + 132 | " \r\n" + 133 | " \r\n" + 134 | " \r\n" + 135 | " \r\n" + 136 | " \r\n" + 137 | " "); 138 | 139 | if (filetotal != null) { 140 | 141 | 142 | for (ArrayList fli : filetotal) { 143 | String d = (String)fli.get(1); 144 | String si = null; 145 | if (fli.get(4).equals("DIR")) { 146 | 147 | String i = req.getServletContext().getRealPath(".").substring(0,req.getServletContext().getRealPath(".").lastIndexOf(sepp)) + sepp + "userfile" + sepp + name + "qiandu" + fli.get(1) + fli.get(0); 148 | File f = new File(i); 149 | Double size = FileUtil.getTotalSizeOfFilesInDir(f)/1024.0; 150 | if (size < 1024) { 151 | si = (String.format("%.2fKB", size)); 152 | } else { 153 | si = (String.format("%.2fMB", size/1024.0)); 154 | } 155 | out.print("\r\n" + 156 | " \r\n" + 157 | " \r\n" + 158 | " \r\n" + 159 | " \r\n" + 160 | " \r\n" + 161 | " \r\n" + 162 | " \r\n" + 163 | " \r\n" + 164 | " "); 165 | } else { 166 | Double size = Long.valueOf((String)fli.get(2))/1024.0; 167 | if (size < 1024) { 168 | si = (String.format("%.2fKB", size)); 169 | } else { 170 | si = (String.format("%.2fMB", size/1024.0)); 171 | } 172 | out.print("\r\n" + 173 | " \r\n" + 174 | " \r\n" + 175 | " \r\n" + 176 | " \r\n" + 177 | " \r\n" + 178 | " \r\n" + 179 | " \r\n" + 180 | " \r\n" + 181 | " "); 182 | } 183 | 184 | 185 | } 186 | 187 | 188 | 189 | } else { 190 | out.print("\r\n" + 191 | " \r\n" + 192 | " "); 193 | } 194 | 195 | 196 | 197 | out.print("
文件名资源路径大小上传日期类型操作
"+fli.get(0)+""+fli.get(1)+""+si+""+fli.get(3)+""+fli.get(4)+"删除
"+fli.get(0)+""+fli.get(1)+""+si+""+fli.get(3)+""+fli.get(4)+"删除分享 下载
对不起,没有找到文件了
\r\n" + 198 | "
\r\n" + 199 | "
\r\n" + 200 | "
\r\n" + 201 | "
\r\n" + 202 | "
\r\n" + 203 | "
\r\n" + 204 | " \r\n" + 205 | ""); 206 | 207 | 208 | 209 | 210 | } 211 | 212 | public void doPost(HttpServletRequest req, HttpServletResponse res) 213 | throws ServletException, IOException { 214 | 215 | this.doGet(req, res); 216 | } 217 | 218 | } 219 | -------------------------------------------------------------------------------- /WebContent/css/reset.css: -------------------------------------------------------------------------------- 1 | body{ 2 | margin:0 auto; 3 | padding:0; 4 | min-width:1024px; 5 | } 6 | #all a{ 7 | text-decoration:none; 8 | outline: none; 9 | hide-focus: expression(this.hideFocus=true); 10 | } 11 | #all a:hover{ 12 | color:#0060BF; 13 | } 14 | .top{ 15 | position:relative; 16 | } 17 | .navbar-brand img{ 18 | height:30px; 19 | float:left; 20 | } 21 | .navbar-brand p{ 22 | float:right; 23 | margin-bottom: 0rem; 24 | margin-left:10px; 25 | } 26 | .nav li{ 27 | padding-right:30px; 28 | } 29 | .top .navbar { 30 | border-radius: 0rem; 31 | } 32 | .nav_width{ 33 | margin:0 auto; 34 | } 35 | .nav_width p{ 36 | font-famliy:"微软雅黑"; 37 | font-size:20px; 38 | font-weight:600; 39 | } 40 | .login label{ 41 | display:block; 42 | } 43 | .login{ 44 | position: absolute; 45 | z-index: 1000; 46 | width:300px; 47 | top:20%; 48 | right:15%; 49 | background-color:#fff; 50 | padding:30px; 51 | box-shadow: 0px 0px 2px rgba(0, 0, 0, 0.13), 0px 1px 5px rgba(0, 0, 0, 0.36), 0px 0px 0px 1px rgba(255, 255, 255, 0.69) inset; 52 | } 53 | .login_in{ 54 | margin:0 auto; 55 | text-align:left; 56 | } 57 | .login_in p{ 58 | color:#0275D8; 59 | } 60 | #fault{ 61 | width:200px; 62 | height:16px; 63 | background-image:url(../images/falut.png); 64 | background-repeat:no-repeat; 65 | display:none; 66 | } 67 | .alerterro { 68 | height:16px; 69 | margin:6px 0; 70 | } 71 | 72 | .alerterro span{ 73 | padding-left:25px; 74 | font-size:14px; 75 | color:#666; 76 | font-style:normal; 77 | } 78 | .btn{ 79 | width:220px; 80 | } 81 | .verification input{ 82 | width:125px; 83 | margin-right:15px; 84 | float:left; 85 | } 86 | .verification img{ 87 | width:90px; 88 | height:35px; 89 | float:right; 90 | } 91 | .middle{ 92 | max-width:1100px; 93 | margin:0 auto; 94 | margin-bottom:40px; 95 | } 96 | .middle_nav{ 97 | width:200px; 98 | height:35px; 99 | margin:30px 0 30px 0; 100 | font-size:20px; 101 | font-family:"微软雅黑"; 102 | background-image:url(../images/navback.jpg); 103 | background-repeat:no-repeat; 104 | } 105 | .mid_title { 106 | text-align:center; 107 | margin:0 auto; 108 | 109 | } 110 | .mid_title p{ 111 | font-size:20px; 112 | color:#474775; 113 | font-family:"微软雅黑"; 114 | font-weight:600; 115 | } 116 | .footer{ 117 | margin-top:20px; 118 | font-size:14px; 119 | text-align:center; 120 | color:#999; 121 | } 122 | .rborder{ 123 | border:1px solid #fff; 124 | border-right-color:#ccc; 125 | } 126 | 127 | 128 | #main-nav { 129 | background-color:#F5F5F5; 130 | padding:20px 15px 0 15px; 131 | min-height:650px; 132 | } 133 | 134 | #main-nav li{ 135 | padding:10px; 136 | text-align:center; 137 | 138 | } 139 | #main-nav li a{ 140 | color:#333333; 141 | } 142 | .nav-tabs { 143 | border:none; 144 | } 145 | .rightarea{ 146 | padding:20px; 147 | min-height:650px; 148 | border:1px solid #F0F0F0; 149 | box-shadow: 0px 0px 3px rgba(0, 0, 0, 0.13), 0px 0px 0px rgba(0, 0, 0, 0.36), 0px 0px 0px 0px rgba(255, 255, 255, 0.69) inset; 150 | } 151 | .rightarea button{ 152 | width:100px; 153 | } 154 | .righthead{ 155 | margin-bottom:10px; 156 | } 157 | .searchf p{ 158 | float:left; 159 | } 160 | .searchf .input-group{ 161 | width:260px; 162 | margin-bottom:20px; 163 | float:right; 164 | } 165 | .table tr:hover{ 166 | background-color:#F7F9FD; 167 | } 168 | .table th, .table td { 169 | padding: 0.5rem; 170 | } 171 | .admin{ 172 | margin-top:28px; 173 | padding:0px 20px; 174 | text-align:center; 175 | } 176 | .admin p{ 177 | margin:10px; 178 | } 179 | .admin img{ 180 | width:110px; 181 | height:110px; 182 | border:1px solid #999; 183 | } 184 | .admin a{ 185 | color:#333; 186 | } 187 | .admin .table a:focus, a:hover{ 188 | color:#0080FF; 189 | } 190 | .admin i{ 191 | padding-right:20px; 192 | } 193 | .filefound{ 194 | box-shadow: 0px 0px 3px rgba(0, 0, 0, 0.13), 0px 0px 0px rgba(0, 0, 0, 0.36), 0px 0px 0px 0px rgba(255, 255, 255, 0.69) inset; 195 | max-width:1100px; 196 | min-height:600px; 197 | margin-top:20px; 198 | margin-left:20px; 199 | margin-right:50px; 200 | padding:30px; 201 | } 202 | .filefound button { 203 | width:130px; 204 | } 205 | .found{ 206 | box-shadow: 0px 0px 3px rgba(0, 0, 0, 0.13), 0px 0px 0px rgba(0, 0, 0, 0.36), 0px 0px 0px 0px rgba(255, 255, 255, 0.69) inset; 207 | max-width:1100px; 208 | min-height:600px; 209 | margin-top:20px; 210 | margin-left:20px; 211 | margin-right:50px; 212 | } 213 | .found img{ 214 | margin-top:200px; 215 | vertical-align:central; 216 | } 217 | .ftitle{ 218 | float:left; 219 | margin:30px 0 0 30px; 220 | color:#333; 221 | } 222 | .found i{ 223 | margin-right:10px; 224 | } 225 | .found p{ 226 | text-align:center; 227 | } 228 | .found .btn{ 229 | width:100px; 230 | float:right; 231 | margin:20px 20px; 232 | } 233 | .size{ 234 | font-size:14px; 235 | color:#999; 236 | margin-top:20px; 237 | } 238 | .sign_middle { 239 | max-width:1000px; 240 | margin:0 auto; 241 | box-shadow: 0px 0px 2px rgba(0, 0, 0, 0.13), 0px 0px 0px rgba(0, 0, 0, 0.36), 0px 0px 0px 0px rgba(255, 255, 255, 0.69) inset; 242 | min-height:600px; 243 | } 244 | .signtitle { 245 | background-image: url(../images/sign.jpg); 246 | background-repeat: no-repeat; 247 | height:40px; 248 | margin:30px 0 30px 30px; 249 | text-align:right; 250 | } 251 | .inputlist{ 252 | margin-left:50px; 253 | } 254 | 255 | .sign_middle .input-group input{ 256 | width:350px; 257 | float:right; 258 | margin:15px; 259 | } 260 | .inputlist .input-group .btn{ 261 | margin-top:40px; 262 | margin-left:85px; 263 | width:250px; 264 | } 265 | .sign_middle p{ 266 | float:right; 267 | font-size:14px; 268 | color:#666; 269 | margin:20px; 270 | } 271 | .sign_middle .proof input{ 272 | width:150px; 273 | float:right; 274 | } 275 | .sign_middle .proof img{ 276 | float:right; 277 | margin:15px; 278 | height:38px; 279 | } 280 | .sign_middle .proof a{ 281 | float:right; 282 | margin:15px; 283 | } 284 | .sign_middle label{ 285 | width:50px; 286 | text-align:right; 287 | float:left; 288 | line-height:60px; 289 | } 290 | .sign_middle .btn-lg, .btn-group-lg > .btn{ 291 | padding: 0.4rem 1rem; 292 | } 293 | .sign_middle button{ 294 | margin:40px 170px; 295 | } 296 | .signsucess{ 297 | width:400px; 298 | margin:0 auto; 299 | margin-top:200px; 300 | } 301 | .signsucess img{ 302 | width:80px; 303 | float:left; 304 | margin-right:20px; 305 | } 306 | .signsucess h3{ 307 | padding-top:15px; 308 | font-family:"微软雅黑"; 309 | } 310 | .remodal-bg{ 311 | display:block; 312 | float:right; 313 | margin-top:23px; 314 | margin-right:25px; 315 | } 316 | .fmall{ 317 | margin:0 auto; 318 | } 319 | .fmtable{ 320 | margin-top:20px; 321 | } 322 | .fmlist{ 323 | margin:0 20px; 324 | 325 | } 326 | .fmadmin img{ 327 | border:1px solid #999; 328 | margin-top:20px; 329 | margin-left:20px; 330 | } 331 | .fmlist p{ 332 | line-height:16px; 333 | margin-bottom:0px; 334 | } 335 | .fmlist a img{ 336 | margin-right:15px; 337 | } 338 | .fmlist .dropdown { 339 | display:inline; 340 | } 341 | .fmlist .dropdown-menu{ 342 | min-width:100px; 343 | } 344 | .fmlist .dropdown li{ 345 | padding-left:20px; 346 | } 347 | .fp p{ 348 | line-height:16px; 349 | margin-bottom:0px; 350 | margin-top:7px; 351 | } 352 | .fp a{ 353 | margin-right:20px; 354 | } 355 | .exe{ 356 | background-image:url(../images/exe.jpg); 357 | background-repeat:no-repeat; 358 | padding-left:30px; 359 | } 360 | .jpg{ 361 | background-image:url(../images/jepg.jpg); 362 | background-repeat:no-repeat; 363 | padding-left:30px; 364 | } 365 | .apk{ 366 | background-image:url(../images/apk.jpg); 367 | background-repeat:no-repeat; 368 | padding-left:30px; 369 | } 370 | .mp3{ 371 | background-image:url(../images/music.jpg); 372 | background-repeat:no-repeat; 373 | padding-left:30px; 374 | } 375 | .zip{ 376 | background-image:url(../images/zip.jpg); 377 | background-repeat:no-repeat; 378 | padding-left:30px; 379 | } 380 | .others{ 381 | background-image:url(../images/others.jpg); 382 | background-repeat:no-repeat; 383 | padding-left:30px; 384 | } 385 | .mp4{ 386 | background-image:url(../images/video.jpg); 387 | background-repeat:no-repeat; 388 | padding-left:30px; 389 | } 390 | .fmback{ 391 | max-width:1100px; 392 | background-image:url(../images/back1.jpg); 393 | padding-left:50px; 394 | } 395 | .fmtable .table a{ 396 | color:#333; 397 | } 398 | .fmtable .table td{ 399 | width:20px; 400 | } 401 | .fmlist .table td{ 402 | padding:0.8em; 403 | } 404 | .fmlist .table a{ 405 | color:#333; 406 | } 407 | #fmtable .table-hover tbody tr:hover { 408 | background-color: #F0F0F0; 409 | } 410 | #fmtable td{ 411 | border:none; 412 | line-height:0.5em; 413 | } 414 | #fmtable p{ 415 | padding-top:25px; 416 | } 417 | #fmtable table{ 418 | width:250px; 419 | margin-top:15px; 420 | margin-left:-10px; 421 | } 422 | .fmreback{ 423 | background-image:url(../images/reback1.jpg); 424 | background-repeat:repeat-x; 425 | } 426 | .fmtime{ 427 | text-align:center; 428 | } 429 | .filefound .form-inline{ 430 | width:600px; 431 | margin:0 auto; 432 | margin-top:200px; 433 | } 434 | .myprogress { 435 | width:600px; 436 | margin:0px 0 20px 0; 437 | } 438 | .myprogress .progress{ 439 | width:500px; 440 | float:left; 441 | } 442 | .myprogress .myprogress_text{ 443 | float:right; 444 | line-height:15px; 445 | } -------------------------------------------------------------------------------- /src/view/PublicShareView.java: -------------------------------------------------------------------------------- 1 | package view; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | import java.io.PrintWriter; 6 | import java.net.URLEncoder; 7 | import java.util.ArrayList; 8 | import java.util.Arrays; 9 | 10 | import javax.servlet.ServletException; 11 | import javax.servlet.http.HttpServlet; 12 | import javax.servlet.http.HttpServletRequest; 13 | import javax.servlet.http.HttpServletResponse; 14 | 15 | import util.FileUtil; 16 | 17 | public class PublicShareView extends HttpServlet { 18 | 19 | public void doGet(HttpServletRequest req, HttpServletResponse res) 20 | throws ServletException, IOException { 21 | req.setCharacterEncoding("utf-8"); 22 | res.setContentType("text/html;charset=utf-8"); 23 | PrintWriter out = res.getWriter(); 24 | String sep = "/|\\\\"; 25 | String sepp = System.getProperty("file.separator"); 26 | 27 | String name = (String) req.getAttribute("name"); 28 | String dir = null; 29 | if (req.getParameter("dir")==null || req.getParameter("dir").equals("")) { 30 | dir = sepp; 31 | } else { 32 | dir = (String)req.getParameter("dir"); 33 | } 34 | ArrayList filetotal = (ArrayList) req.getAttribute("filetotal"); 35 | ArrayList dirtotal = (ArrayList) req.getAttribute("dirtotal"); 36 | 37 | if (dir == null || dir.equals("")) { 38 | dir = sepp; 39 | } 40 | 41 | String userpath = "." + sepp + "userfile" + sepp + name + "qiandu"; 42 | Double size = FileUtil.getTotalSizeOfFilesInDir(new File(userpath))/1024.0; 43 | String si = null; 44 | if (size < 1024) { 45 | si = String.format("%.2fKB", size); 46 | } else { 47 | si = String.format("%.2fMB", size/1024.0); 48 | } 49 | 50 | 51 | out.print("\r\n" + 52 | "\r\n" + 53 | "\r\n" + 54 | "\r\n" + 55 | "\r\n" + 56 | " \r\n" + 57 | " \r\n" + 58 | " \r\n" + 59 | " 千度网盘\r\n" + 60 | " \r\n" + 61 | " \r\n" + 62 | " \r\n" + 63 | " \r\n" + 64 | " \r\n" + 65 | " \r\n" + 77 | "\r\n" + 78 | "\r\n" + 79 | "\r\n" + 80 | "\r\n" + 81 | "
\r\n" + 82 | " \r\n" + 83 | "
\r\n" + 84 | " \r\n" + 107 | "
\r\n" + 108 | "
\r\n" + 109 | "
\r\n" + 110 | "
\r\n" + 111 | "
\r\n" + 112 | "
\r\n" + 113 | " \r\n" + 114 | "

"+name+"

\r\n" + 115 | " \r\n" + 116 | " \r\n" + 117 | " \r\n" + 118 | " \r\n" + 119 | " \r\n" + 120 | " \r\n" + 121 | "\r\n" + 122 | " \r\n" + 123 | "\r\n" + 124 | " \r\n" + 125 | "\r\n" + 126 | " \r\n" + 127 | "
空间占用等级
"+si+"普通用户
\r\n" + 128 | "
\r\n" + 129 | "
\r\n" + 130 | "
\r\n" + 131 | "\r\n" + 132 | "
\r\n" + 133 | "
\r\n" + 134 | "

公共分享

\r\n" + 135 | "\r\n" + 136 | " \r\n" + 139 | "
\r\n" + 140 | " \r\n" + 141 | "
\r\n" + 142 | " \r\n" + 143 | "\r\n" + 144 | "
\r\n" + 145 | "
\r\n" + 146 | " \r\n" + 147 | " \r\n" + 148 | "
\r\n" + 149 | " \r\n" + 150 | "\r\n" + 151 | "
"); 152 | 153 | 154 | out.print("公共资源>> \r\n"); 155 | 156 | String m = sepp; 157 | for (String str : Arrays.asList(dir.split(sep))) { 158 | if (!str.trim().equals("")) { 159 | m += str+sepp; 160 | out.print(""+str+">> \r\n"); 161 | } 162 | } 163 | 164 | 165 | 166 | out.print("\r\n" + 167 | " \r\n" + 168 | " \r\n" + 169 | " \r\n" + 170 | " \r\n" + 171 | " \r\n" + 172 | " \r\n" + 173 | " \r\n" + 174 | " \r\n" + 175 | " "); 176 | 177 | if (!(filetotal.isEmpty() && dirtotal.isEmpty())) { 178 | for (ArrayList dli : dirtotal) { 179 | out.print("\r\n" + 180 | " \r\n" + 181 | " \r\n" + 182 | " \r\n" + 183 | " \r\n" + 184 | " \r\n" + 185 | " \r\n" + 186 | " \r\n" + 187 | " \r\n" + 188 | " "); 189 | 190 | } 191 | 192 | for (ArrayList fli : filetotal) { 193 | out.print("\r\n" + 194 | " \r\n" + 195 | " \r\n" + 196 | " \r\n" + 197 | " \r\n" + 198 | " \r\n" + 199 | " \r\n" + 200 | " \r\n" + 201 | " \r\n" + 202 | " "); 203 | 204 | } 205 | 206 | 207 | 208 | } else { 209 | out.print("\r\n" + 210 | " \r\n" + 211 | " "); 212 | } 213 | 214 | out.print("
文件名上传者上传时间大小类型操作
"+dli.get(0)+"-"+dli.get(1)+""+dli.get(2)+""+dli.get(3)+"宁没有权限
"+fli.get(0)+""+fli.get(1)+""+fli.get(2)+""+fli.get(3)+""+fli.get(4)+"下载
对不起,没有文件了
\r\n" + 215 | "
\r\n" + 216 | "
\r\n" + 217 | "
\r\n" + 218 | "
\r\n" + 219 | "
\r\n" + 220 | "
\r\n" + 221 | " \r\n" + 222 | "\r\n" + 223 | ""); 224 | 225 | 226 | 227 | 228 | } 229 | 230 | public void doPost(HttpServletRequest req, HttpServletResponse res) 231 | throws ServletException, IOException { 232 | 233 | this.doGet(req, res); 234 | } 235 | 236 | } 237 | 238 | -------------------------------------------------------------------------------- /src/view/PublicManagerView.java: -------------------------------------------------------------------------------- 1 | package view; 2 | 3 | import util.FileUtil; 4 | 5 | import java.io.IOException; 6 | import java.io.PrintWriter; 7 | import java.net.URLEncoder; 8 | import java.util.ArrayList; 9 | import java.util.Arrays; 10 | 11 | import javax.servlet.ServletException; 12 | import javax.servlet.http.HttpServlet; 13 | import javax.servlet.http.HttpServletRequest; 14 | import javax.servlet.http.HttpServletResponse; 15 | 16 | public class PublicManagerView extends HttpServlet { 17 | 18 | public void doGet(HttpServletRequest req, HttpServletResponse res) 19 | throws ServletException, IOException { 20 | req.setCharacterEncoding("utf-8"); 21 | res.setContentType("text/html;charset=utf-8"); 22 | PrintWriter out = res.getWriter(); 23 | String sep = "/|\\\\"; 24 | String sepp = System.getProperty("file.separator"); 25 | String dir = (String) req.getAttribute("dir"); 26 | ArrayList filetotal = (ArrayList) req.getAttribute("filetotal"); 27 | ArrayList dirtotal = (ArrayList) req.getAttribute("dirtotal"); 28 | 29 | if (dir == null || dir.equals("")) { 30 | dir = sepp; 31 | } 32 | 33 | out.print("\r\n" + 34 | "\r\n" + 35 | "\r\n" + 36 | "\r\n" + 37 | "\r\n" + 38 | " \r\n" + 39 | " \r\n" + 40 | " \r\n" + 41 | " 千度网盘\r\n" + 42 | " \r\n" + 43 | " \r\n" + 44 | " \r\n" + 45 | " \r\n" + 46 | " \r\n" + 58 | "\r\n" + 59 | "\r\n" + 60 | "\r\n" + 61 | "\r\n" + 62 | "
\r\n" + 63 | " \r\n" + 64 | "
\r\n" + 65 | " \r\n" + 85 | "
\r\n" + 86 | "
\r\n" + 87 | "
\r\n" + 88 | "
\r\n" + 89 | "
\r\n" + 90 | "
\r\n" + 91 | " \r\n" + 92 | "

Admin

\r\n" + 93 | " \r\n" + 94 | " \r\n" + 95 | " \r\n" + 96 | " \r\n" + 97 | " \r\n" + 98 | " \r\n" + 99 | "\r\n" + 100 | " \r\n" + 101 | "\r\n" + 102 | " \r\n" + 103 | "\r\n" + 104 | " \r\n" + 105 | "
空间占用等级
+∞ROOT
\r\n" + 106 | "
\r\n" + 107 | "
\r\n" + 108 | "
\r\n" + 109 | "\r\n" + 110 | "
\r\n" + 111 | "
\r\n" + 112 | "

公共资源管理

\r\n" + 113 | "\r\n" + 114 | " \r\n" + 117 | "
\r\n" + 118 | " \r\n" + 119 | "
\r\n" + 120 | " \r\n" + 121 | "\r\n" + 122 | "
\r\n" + 123 | " \r\n" + 126 | "\r\n" + 127 | "
\r\n" + 128 | "
\r\n" + 129 | " \r\n" + 130 | " \r\n" + 131 | "
\r\n" + 132 | " \r\n" + 133 | "\r\n" + 134 | "
"); 135 | 136 | 137 | out.print("公共资源管理>> \r\n"); 138 | 139 | String m = sepp; 140 | for (String str : Arrays.asList(dir.split(sep))) { 141 | if (!str.trim().equals("")) { 142 | m += str + sepp; 143 | out.print(""+str+">> \r\n"); 144 | } 145 | } 146 | 147 | 148 | 149 | 150 | out.print("\r\n" + 151 | " \r\n" + 152 | " \r\n" + 153 | " \r\n" + 154 | " \r\n" + 155 | " \r\n" + 156 | " \r\n" + 157 | " \r\n" + 158 | " \r\n" + 159 | " "); 160 | 161 | if (!(filetotal.isEmpty() && dirtotal.isEmpty())) { 162 | 163 | for (ArrayList dli : dirtotal) { 164 | out.print("\r\n" + 165 | " \r\n" + 166 | " \r\n" + 167 | " \r\n" + 168 | " \r\n" + 169 | " \r\n" + 170 | " \r\n" + 171 | " \r\n" + 172 | " \r\n" + 173 | " "); 174 | 175 | } 176 | 177 | for (ArrayList fli : filetotal) { 178 | out.print("\r\n" + 179 | " \r\n" + 180 | " \r\n" + 181 | " \r\n" + 182 | " \r\n" + 183 | " \r\n" + 184 | " \r\n" + 185 | " \r\n" + 186 | " \r\n" + 187 | " "); 188 | 189 | } 190 | 191 | 192 | 193 | } else { 194 | out.print("\r\n" + 195 | " \r\n" + 196 | " "); 197 | } 198 | 199 | out.print("
文件名上传者上传时间大小类型操作
"+dli.get(0)+"-"+dli.get(1)+""+dli.get(2)+""+dli.get(3)+"删除
"+fli.get(0)+""+fli.get(1)+""+fli.get(2)+""+fli.get(3)+""+fli.get(4)+"删除下载
对不起,没有文件了
\r\n" + 200 | "
\r\n" + 201 | "
\r\n" + 202 | "
\r\n" + 203 | "
\r\n" + 204 | "
\r\n" + 205 | "
\r\n" + 206 | " \r\n" + 207 | "\r\n" + 208 | " \r\n" + 225 | "\r\n" + 226 | ""); 227 | 228 | 229 | 230 | 231 | } 232 | 233 | public void doPost(HttpServletRequest req, HttpServletResponse res) 234 | throws ServletException, IOException { 235 | 236 | this.doGet(req, res); 237 | } 238 | 239 | } 240 | 241 | -------------------------------------------------------------------------------- /src/view/Main.java: -------------------------------------------------------------------------------- 1 | package view; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | import java.io.PrintWriter; 6 | import java.net.URLEncoder; 7 | import java.util.ArrayList; 8 | import java.util.Arrays; 9 | 10 | import javax.servlet.ServletException; 11 | import javax.servlet.http.HttpServlet; 12 | import javax.servlet.http.HttpServletRequest; 13 | import javax.servlet.http.HttpServletResponse; 14 | 15 | import util.FileUtil; 16 | 17 | public class Main extends HttpServlet { 18 | 19 | public void doGet(HttpServletRequest req, HttpServletResponse res) 20 | throws ServletException, IOException { 21 | req.setCharacterEncoding("utf-8"); 22 | res.setContentType("text/html;charset=utf-8"); 23 | PrintWriter out = res.getWriter(); 24 | String sep = "/|\\\\"; 25 | String sepp = System.getProperty("file.separator"); 26 | 27 | String name = (String) req.getAttribute("name"); 28 | ArrayList filetotal = (ArrayList) req.getAttribute("filetotal"); 29 | ArrayList dirtotal = (ArrayList) req.getAttribute("dirtotal"); 30 | String dir = null; 31 | if (req.getParameter("dir")==null || req.getParameter("dir").equals("")) { 32 | dir = sepp; 33 | } else { 34 | dir = (String)req.getParameter("dir"); 35 | } 36 | 37 | String userpath = "." + sepp + "userfile" + sepp + name + "qiandu"; 38 | Double size = FileUtil.getTotalSizeOfFilesInDir(new File(userpath))/1024.0; 39 | String si = null; 40 | if (size < 1024) { 41 | si = String.format("%.2fKB", size); 42 | } else { 43 | si = String.format("%.2fMB", size/1024.0); 44 | } 45 | 46 | out.print("\r\n" + 47 | "\r\n" + 48 | "\r\n" + 49 | "\r\n" + 50 | "\r\n" + 51 | " \r\n" + 52 | " \r\n" + 53 | " \r\n" + 54 | " 千度网盘\r\n" + 55 | " \r\n" + 56 | " \r\n" + 57 | " \r\n" + 58 | " \r\n" + 59 | " \r\n" + 71 | "\r\n" + 72 | "\r\n" + 73 | "\r\n" + 74 | "\r\n" + 75 | "
\r\n" + 76 | " \r\n" + 77 | "
\r\n" + 78 | " \r\n" + 101 | "
\r\n" + 102 | "
\r\n" + 103 | "
\r\n" + 104 | "
\r\n" + 105 | "
\r\n" + 106 | "
\r\n" + 107 | " \r\n" + 108 | "

"+name+"

\r\n" + 109 | " \r\n" + 110 | " \r\n" + 111 | " \r\n" + 112 | " \r\n" + 113 | " \r\n" + 114 | " \r\n" + 115 | "\r\n" + 116 | " \r\n" + 117 | " \r\n" + 118 | "\r\n" + 119 | " \r\n" + 120 | "
空间占用等级
"+si+"普通用户
\r\n" + 121 | "
\r\n" + 122 | "
\r\n" + 123 | "
\r\n" + 124 | "\r\n" + 125 | "
\r\n" + 126 | "
\r\n" + 127 | "

我的资源

\r\n" + 128 | "\r\n" + 129 | " \r\n" + 132 | "
\r\n" + 133 | " \r\n" + 134 | "
\r\n" + 135 | " \r\n" + 136 | "\r\n" + 137 | "
\r\n" + 138 | " \r\n" + 141 | " \r\n" + 142 | "\r\n" + 143 | "
\r\n" + 144 | "
\r\n" + 145 | " \r\n" + 146 | " \r\n" + 147 | "
\r\n" + 148 | " \r\n" + 149 | "\r\n" + 150 | "
"); 151 | 152 | 153 | out.print("我的资源>> \r\n"); 154 | 155 | String m = sepp; 156 | for (String str : Arrays.asList(dir.split(sep))) { 157 | if (!str.trim().equals("")) { 158 | m += str+sepp; 159 | out.print(""+str+">> \r\n"); 160 | } 161 | } 162 | 163 | 164 | 165 | out.print("\r\n" + 166 | " \r\n" + 167 | " \r\n" + 168 | " \r\n" + 169 | " \r\n" + 170 | " \r\n" + 171 | " \r\n" + 172 | " \r\n" + 173 | " "); 174 | 175 | if (!(filetotal.isEmpty() && dirtotal.isEmpty())) { 176 | 177 | for (ArrayList dli : dirtotal) { 178 | out.print("\r\n" + 179 | " \r\n" + 180 | " \r\n" + 181 | " \r\n" + 182 | " \r\n" + 183 | " \r\n" + 184 | " \r\n" + 185 | " \r\n" + 186 | " "); 187 | 188 | } 189 | 190 | for (ArrayList fli : filetotal) { 191 | out.print("\r\n" + 192 | " \r\n" + 193 | " \r\n" + 194 | " \r\n" + 195 | " \r\n" + 196 | " \r\n" + 197 | " \r\n" + 198 | " \r\n" + 199 | " "); 200 | 201 | } 202 | 203 | 204 | 205 | } else { 206 | out.print("\r\n" + 207 | " \r\n" + 208 | " "); 209 | } 210 | 211 | out.print("
文件名上传日期大小类型操作
"+dli.get(0)+""+dli.get(1)+""+dli.get(2)+""+dli.get(3)+"删除
"+fli.get(0)+""+fli.get(1)+""+fli.get(2)+""+fli.get(3)+"删除分享 下载
对不起,没有文件了
\r\n" + 212 | "
\r\n" + 213 | "
\r\n" + 214 | "
\r\n" + 215 | "
\r\n" + 216 | "
\r\n" + 217 | "
\r\n" + 218 | " \r\n" + 219 | "\r\n" + 220 | "\r\n" + 221 | " \r\n" + 238 | "\r\n" + 239 | ""); 240 | 241 | 242 | 243 | 244 | } 245 | 246 | public void doPost(HttpServletRequest req, HttpServletResponse res) 247 | throws ServletException, IOException { 248 | 249 | this.doGet(req, res); 250 | } 251 | 252 | } 253 | -------------------------------------------------------------------------------- /src/view/UserFileView.java: -------------------------------------------------------------------------------- 1 | package view; 2 | 3 | import util.FileUtil; 4 | 5 | import java.io.IOException; 6 | import java.io.PrintWriter; 7 | import java.net.URLEncoder; 8 | import java.util.ArrayList; 9 | import java.util.Arrays; 10 | 11 | import javax.servlet.ServletException; 12 | import javax.servlet.http.HttpServlet; 13 | import javax.servlet.http.HttpServletRequest; 14 | import javax.servlet.http.HttpServletResponse; 15 | 16 | 17 | public class UserFileView extends HttpServlet { 18 | 19 | public void doGet(HttpServletRequest req, HttpServletResponse res) 20 | throws ServletException, IOException { 21 | req.setCharacterEncoding("utf-8"); 22 | res.setContentType("text/html;charset=utf-8"); 23 | PrintWriter out = res.getWriter(); 24 | String sep = "/|\\\\"; 25 | String sepp = System.getProperty("file.separator"); 26 | 27 | String name = (String) req.getAttribute("name"); 28 | String dir = null; 29 | if (req.getParameter("dir")==null || req.getParameter("dir").equals("")) { 30 | dir = sepp; 31 | } else { 32 | dir = (String)req.getParameter("dir"); 33 | } 34 | ArrayList filetotal = ((ArrayList) req.getAttribute("filetotal"))!=null?((ArrayList) req.getAttribute("filetotal")):new ArrayList(); 35 | ArrayList dirtotal = ((ArrayList) req.getAttribute("dirtotal"))!=null?((ArrayList) req.getAttribute("dirtotal")):new ArrayList(); 36 | 37 | out.print("\r\n" + 38 | "\r\n" + 39 | "\r\n" + 40 | "\r\n" + 41 | "\r\n" + 42 | " \r\n" + 43 | " \r\n" + 44 | " \r\n" + 45 | " 千度网盘\r\n" + 46 | " \r\n" + 47 | " \r\n" + 48 | " \r\n" + 49 | " \r\n" + 50 | " \r\n" + 62 | "\r\n" + 63 | "\r\n" + 64 | "\r\n" + 65 | "\r\n" + 66 | "
\r\n" + 67 | " \r\n" + 68 | "
\r\n" + 69 | " \r\n" + 90 | "
\r\n" + 91 | "
\r\n" + 92 | "
\r\n" + 93 | "
\r\n" + 94 | "
\r\n" + 95 | "
\r\n" + 96 | " \r\n" + 97 | "

Admin

\r\n" + 98 | " \r\n" + 99 | " \r\n" + 100 | " \r\n" + 101 | " \r\n" + 102 | " \r\n" + 103 | " \r\n" + 104 | "\r\n" + 105 | " \r\n" + 106 | "\r\n" + 107 | " \r\n" + 108 | "\r\n" + 109 | " \r\n" + 110 | "
空间占用等级
+∞ROOT
\r\n" + 111 | "
\r\n" + 112 | "
\r\n" + 113 | "
\r\n" + 114 | "\r\n" + 115 | "
\r\n" + 116 | "
\r\n" + 117 | "

用户及资源管理

\r\n" + 118 | "\r\n" + 119 | " \r\n" + 122 | "
\r\n" + 123 | " \r\n" + 124 | "
\r\n" + 125 | " \r\n" + 126 | "\r\n" + 127 | "
\r\n" + 128 | " \r\n" + 131 | " \r\n" + 132 | "\r\n" + 133 | "
\r\n" + 134 | "
\r\n" + 135 | " \r\n" + 136 | " \r\n" + 137 | "
\r\n" + 138 | " \r\n" + 139 | "\r\n" + 140 | "
"); 141 | 142 | 143 | out.print("所有用户>> \r\n"); 144 | out.print(""+name+">> \r\n"); 145 | 146 | String m = sepp; 147 | for (String str : Arrays.asList(dir.split(sep))) { 148 | if (!str.trim().equals("")) { 149 | m += str+sepp; 150 | out.print(""+str+">> \r\n"); 151 | } 152 | } 153 | 154 | 155 | out.print("\r\n" + 156 | " \r\n" + 157 | " \r\n" + 158 | " \r\n" + 159 | " \r\n" + 160 | " \r\n" + 161 | " \r\n" + 162 | " \r\n" + 163 | " "); 164 | 165 | if (!(filetotal.isEmpty() && dirtotal.isEmpty())) { 166 | 167 | for (ArrayList dli : dirtotal) { 168 | out.print("\r\n" + 169 | " \r\n" + 170 | " \r\n" + 171 | " \r\n" + 172 | " \r\n" + 173 | " \r\n" + 174 | " \r\n" + 175 | " \r\n" + 176 | " "); 177 | 178 | } 179 | 180 | for (ArrayList fli : filetotal) { 181 | out.print("\r\n" + 182 | " \r\n" + 183 | " \r\n" + 184 | " \r\n" + 185 | " \r\n" + 186 | " \r\n" + 187 | " \r\n" + 188 | " \r\n" + 189 | " "); 190 | 191 | } 192 | 193 | 194 | 195 | } else { 196 | out.print("\r\n" + 197 | " \r\n" + 198 | " "); 199 | } 200 | 201 | out.print("
文件名上传日期大小类型操作
"+dli.get(0)+""+dli.get(1)+""+dli.get(2)+""+dli.get(3)+"删除
"+fli.get(0)+""+fli.get(1)+""+fli.get(2)+""+fli.get(3)+"删除分享 下载
对不起,没有文件了
\r\n" + 202 | "
\r\n" + 203 | "
\r\n" + 204 | "
\r\n" + 205 | "
\r\n" + 206 | "
\r\n" + 207 | "
\r\n" + 208 | " \r\n" + 209 | "\r\n" + 210 | "\r\n" + 211 | " \r\n" + 229 | "\r\n" + 230 | ""); 231 | 232 | 233 | 234 | 235 | } 236 | 237 | public void doPost(HttpServletRequest req, HttpServletResponse res) 238 | throws ServletException, IOException { 239 | 240 | this.doGet(req, res); 241 | } 242 | 243 | } 244 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------