From a303f56e1236f2bd6dc1ae88e734695a395e9058 Mon Sep 17 00:00:00 2001 From: FJY Date: Sat, 18 Nov 2017 20:28:08 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=AE=BA=E5=9D=9B=E7=A9=BA?= =?UTF-8?q?=E7=99=BD=E8=BE=93=E5=85=A5,=E4=B8=8A=E4=BC=A0=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E6=9C=AA=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .classpath | 5 + .idea/misc.xml | 6 + .idea/modules.xml | 8 + .idea/vcs.xml | 6 + .idea/workspace.xml | 264 ++++++++++++++++++ .settings/org.eclipse.core.resources.prefs | 1 + WebRoot/JSPhandle/docFile_insert.jsp | 87 ++++++ WebRoot/JSPhandle/login_show.jsp | 3 + .../WEB-INF/classes/com/wgh/MySqlconn.class | Bin 0 -> 499 bytes .../gacl/web/controller/DownLoadServlet.class | Bin 0 -> 3552 bytes .../gacl/web/controller/ListFileServlet.class | Bin 0 -> 2542 bytes .../web/controller/UploadHandleServlet.class | Bin 0 -> 5793 bytes WebRoot/WEB-INF/web.xml | 9 + WebRoot/add_docFile.jsp | 157 +++++++++++ WebRoot/css/bootstrap.css | 105 ++----- WebRoot/css/menu-css.css | 55 ++++ WebRoot/detail.jsp | 181 ++++++++---- WebRoot/forum/css/style.css | 5 + WebRoot/forum/deleteComment.jsp | 45 +++ WebRoot/forum/deletesend.jsp | 46 +++ WebRoot/forum/send.jsp | 52 ++-- WebRoot/forum/sendComment.jsp | 7 +- WebRoot/forum/submitDown.jsp | 39 +++ WebRoot/forum/submitTop.jsp | 33 +++ WebRoot/index.jsp | 172 ++++++++---- WebRoot/js/menu_min.js | 51 ++++ WebRoot/login.jsp | 59 ---- WebRoot/login_fail.jsp | 29 -- WebRoot/login_show.jsp | 27 -- WebRoot/mainframe.html | 16 -- WebRoot/mainframe.jsp | 10 +- WebRoot/manage.html | 14 - WebRoot/message.jsp | 12 + WebRoot/module/sidebar.jsp | 2 + WebRoot/module/sidebar_pull.jsp | 74 +++++ WebRoot/send.html | 100 ------- WebRoot/send.jsp | 50 ++-- WebRoot/sendForum.jsp | 137 +++++++++ WebRoot/signin_insert.jsp | 51 ---- WebRoot/top.html | 62 ---- WebRoot/upload.jsp | 16 ++ WebRoot/x2_resource.jsp | 43 ++- src/com/wgh/MySqlconn.java | 7 + src/com/wgh/UserForm.java | 2 +- .../gacl/web/controller/DownLoadServlet.java | 80 ++++++ .../gacl/web/controller/ListFileServlet.java | 67 +++++ .../web/controller/UploadHandleServlet.java | 119 ++++++++ 47 files changed, 1699 insertions(+), 615 deletions(-) create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 .idea/workspace.xml create mode 100644 WebRoot/JSPhandle/docFile_insert.jsp create mode 100644 WebRoot/WEB-INF/classes/com/wgh/MySqlconn.class create mode 100644 WebRoot/WEB-INF/classes/me/gacl/web/controller/DownLoadServlet.class create mode 100644 WebRoot/WEB-INF/classes/me/gacl/web/controller/ListFileServlet.class create mode 100644 WebRoot/WEB-INF/classes/me/gacl/web/controller/UploadHandleServlet.class create mode 100644 WebRoot/add_docFile.jsp create mode 100644 WebRoot/css/menu-css.css create mode 100644 WebRoot/forum/deleteComment.jsp create mode 100644 WebRoot/forum/deletesend.jsp create mode 100644 WebRoot/forum/submitDown.jsp create mode 100644 WebRoot/forum/submitTop.jsp create mode 100644 WebRoot/js/menu_min.js delete mode 100644 WebRoot/login.jsp delete mode 100644 WebRoot/login_fail.jsp delete mode 100644 WebRoot/login_show.jsp delete mode 100644 WebRoot/mainframe.html delete mode 100644 WebRoot/manage.html create mode 100644 WebRoot/message.jsp create mode 100644 WebRoot/module/sidebar_pull.jsp delete mode 100644 WebRoot/send.html create mode 100644 WebRoot/sendForum.jsp delete mode 100644 WebRoot/signin_insert.jsp delete mode 100644 WebRoot/top.html create mode 100644 WebRoot/upload.jsp create mode 100644 src/com/wgh/MySqlconn.java create mode 100644 src/me/gacl/web/controller/DownLoadServlet.java create mode 100644 src/me/gacl/web/controller/ListFileServlet.java create mode 100644 src/me/gacl/web/controller/UploadHandleServlet.java diff --git a/.classpath b/.classpath index cc4564e..e19a7d1 100644 --- a/.classpath +++ b/.classpath @@ -13,5 +13,10 @@ + + + + + diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..639900d --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..c352923 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..832146f --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..350d23c --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,264 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + DEFINITION_ORDER + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 职务 + + + + + 姓名 + + 性别 + + + + + + + 民族 + + 籍贯 + + + + + + + 学校 + + 学院 + + + + 专业 + + 出生年月 + + + + 社交信息 + + + QQ + + 邮箱 + + + + 电话 + + 住址 + + + + 简历 + + + + + + 备注 + + + + + + + + + + <%@ include file="module/footer.jsp"%> + + + + + + \ No newline at end of file diff --git a/WebRoot/css/bootstrap.css b/WebRoot/css/bootstrap.css index 680e768..6167622 100644 --- a/WebRoot/css/bootstrap.css +++ b/WebRoot/css/bootstrap.css @@ -1,6 +1,6 @@ /*! - * Bootstrap v3.3.5 (http://getbootstrap.com) - * Copyright 2011-2015 Twitter, Inc. + * Bootstrap v3.3.7 (http://getbootstrap.com) + * Copyright 2011-2016 Twitter, Inc. * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE) */ /*! normalize.css v3.0.3 | MIT License | github.com/necolas/normalize.css */ @@ -279,10 +279,10 @@ th { -moz-osx-font-smoothing: grayscale; } .glyphicon-asterisk:before { - content: "\2a"; + content: "\002a"; } .glyphicon-plus:before { - content: "\2b"; + content: "\002b"; } .glyphicon-euro:before, .glyphicon-eur:before { @@ -1106,7 +1106,6 @@ a:focus { text-decoration: underline; } a:focus { - outline: thin dotted; outline: 5px auto -webkit-focus-ring-color; outline-offset: -2px; } @@ -2537,7 +2536,6 @@ select[size] { input[type="file"]:focus, input[type="radio"]:focus, input[type="checkbox"]:focus { - outline: thin dotted; outline: 5px auto -webkit-focus-ring-color; outline-offset: -2px; } @@ -2582,6 +2580,10 @@ output { .form-control::-webkit-input-placeholder { color: #999; } +.form-control::-ms-expand { + background-color: transparent; + border: 0; +} .form-control[disabled], .form-control[readonly], fieldset[disabled] .form-control { @@ -2988,7 +2990,7 @@ select[multiple].input-lg { } @media (min-width: 768px) { .form-horizontal .form-group-lg .control-label { - padding-top: 14.333333px; + padding-top: 11px; font-size: 18px; } } @@ -3025,7 +3027,6 @@ select[multiple].input-lg { .btn.focus, .btn:active.focus, .btn.active.focus { - outline: thin dotted; outline: 5px auto -webkit-focus-ring-color; outline-offset: -2px; } @@ -3096,9 +3097,6 @@ fieldset[disabled] a.btn { .open > .dropdown-toggle.btn-default { background-image: none; } -.btn-default.disabled, -.btn-default[disabled], -fieldset[disabled] .btn-default, .btn-default.disabled:hover, .btn-default[disabled]:hover, fieldset[disabled] .btn-default:hover, @@ -3107,13 +3105,7 @@ fieldset[disabled] .btn-default:hover, fieldset[disabled] .btn-default:focus, .btn-default.disabled.focus, .btn-default[disabled].focus, -fieldset[disabled] .btn-default.focus, -.btn-default.disabled:active, -.btn-default[disabled]:active, -fieldset[disabled] .btn-default:active, -.btn-default.disabled.active, -.btn-default[disabled].active, -fieldset[disabled] .btn-default.active { +fieldset[disabled] .btn-default.focus { background-color: #fff; border-color: #ccc; } @@ -3162,9 +3154,6 @@ fieldset[disabled] .btn-default.active { .open > .dropdown-toggle.btn-primary { background-image: none; } -.btn-primary.disabled, -.btn-primary[disabled], -fieldset[disabled] .btn-primary, .btn-primary.disabled:hover, .btn-primary[disabled]:hover, fieldset[disabled] .btn-primary:hover, @@ -3173,13 +3162,7 @@ fieldset[disabled] .btn-primary:hover, fieldset[disabled] .btn-primary:focus, .btn-primary.disabled.focus, .btn-primary[disabled].focus, -fieldset[disabled] .btn-primary.focus, -.btn-primary.disabled:active, -.btn-primary[disabled]:active, -fieldset[disabled] .btn-primary:active, -.btn-primary.disabled.active, -.btn-primary[disabled].active, -fieldset[disabled] .btn-primary.active { +fieldset[disabled] .btn-primary.focus { background-color: #337ab7; border-color: #2e6da4; } @@ -3228,9 +3211,6 @@ fieldset[disabled] .btn-primary.active { .open > .dropdown-toggle.btn-success { background-image: none; } -.btn-success.disabled, -.btn-success[disabled], -fieldset[disabled] .btn-success, .btn-success.disabled:hover, .btn-success[disabled]:hover, fieldset[disabled] .btn-success:hover, @@ -3239,13 +3219,7 @@ fieldset[disabled] .btn-success:hover, fieldset[disabled] .btn-success:focus, .btn-success.disabled.focus, .btn-success[disabled].focus, -fieldset[disabled] .btn-success.focus, -.btn-success.disabled:active, -.btn-success[disabled]:active, -fieldset[disabled] .btn-success:active, -.btn-success.disabled.active, -.btn-success[disabled].active, -fieldset[disabled] .btn-success.active { +fieldset[disabled] .btn-success.focus { background-color: #5cb85c; border-color: #4cae4c; } @@ -3294,9 +3268,6 @@ fieldset[disabled] .btn-success.active { .open > .dropdown-toggle.btn-info { background-image: none; } -.btn-info.disabled, -.btn-info[disabled], -fieldset[disabled] .btn-info, .btn-info.disabled:hover, .btn-info[disabled]:hover, fieldset[disabled] .btn-info:hover, @@ -3305,13 +3276,7 @@ fieldset[disabled] .btn-info:hover, fieldset[disabled] .btn-info:focus, .btn-info.disabled.focus, .btn-info[disabled].focus, -fieldset[disabled] .btn-info.focus, -.btn-info.disabled:active, -.btn-info[disabled]:active, -fieldset[disabled] .btn-info:active, -.btn-info.disabled.active, -.btn-info[disabled].active, -fieldset[disabled] .btn-info.active { +fieldset[disabled] .btn-info.focus { background-color: #5bc0de; border-color: #46b8da; } @@ -3360,9 +3325,6 @@ fieldset[disabled] .btn-info.active { .open > .dropdown-toggle.btn-warning { background-image: none; } -.btn-warning.disabled, -.btn-warning[disabled], -fieldset[disabled] .btn-warning, .btn-warning.disabled:hover, .btn-warning[disabled]:hover, fieldset[disabled] .btn-warning:hover, @@ -3371,13 +3333,7 @@ fieldset[disabled] .btn-warning:hover, fieldset[disabled] .btn-warning:focus, .btn-warning.disabled.focus, .btn-warning[disabled].focus, -fieldset[disabled] .btn-warning.focus, -.btn-warning.disabled:active, -.btn-warning[disabled]:active, -fieldset[disabled] .btn-warning:active, -.btn-warning.disabled.active, -.btn-warning[disabled].active, -fieldset[disabled] .btn-warning.active { +fieldset[disabled] .btn-warning.focus { background-color: #f0ad4e; border-color: #eea236; } @@ -3426,9 +3382,6 @@ fieldset[disabled] .btn-warning.active { .open > .dropdown-toggle.btn-danger { background-image: none; } -.btn-danger.disabled, -.btn-danger[disabled], -fieldset[disabled] .btn-danger, .btn-danger.disabled:hover, .btn-danger[disabled]:hover, fieldset[disabled] .btn-danger:hover, @@ -3437,13 +3390,7 @@ fieldset[disabled] .btn-danger:hover, fieldset[disabled] .btn-danger:focus, .btn-danger.disabled.focus, .btn-danger[disabled].focus, -fieldset[disabled] .btn-danger.focus, -.btn-danger.disabled:active, -.btn-danger[disabled]:active, -fieldset[disabled] .btn-danger:active, -.btn-danger.disabled.active, -.btn-danger[disabled].active, -fieldset[disabled] .btn-danger.active { +fieldset[disabled] .btn-danger.focus { background-color: #d9534f; border-color: #d43f3a; } @@ -3817,6 +3764,7 @@ tbody.collapse.in { border-radius: 0; } .btn-group-vertical > .btn:first-child:not(:last-child) { + border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 0; border-bottom-left-radius: 0; @@ -3824,6 +3772,7 @@ tbody.collapse.in { .btn-group-vertical > .btn:last-child:not(:first-child) { border-top-left-radius: 0; border-top-right-radius: 0; + border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; } .btn-group-vertical > .btn-group:not(:first-child):not(:last-child) > .btn { @@ -3881,6 +3830,9 @@ tbody.collapse.in { width: 100%; margin-bottom: 0; } +.input-group .form-control:focus { + z-index: 3; +} .input-group-lg > .form-control, .input-group-lg > .input-group-addon, .input-group-lg > .input-group-btn > .btn { @@ -4792,7 +4744,7 @@ fieldset[disabled] .navbar-inverse .btn-link:focus { .pagination > li > span:hover, .pagination > li > a:focus, .pagination > li > span:focus { - z-index: 3; + z-index: 2; color: #23527c; background-color: #eee; border-color: #ddd; @@ -4803,7 +4755,7 @@ fieldset[disabled] .navbar-inverse .btn-link:focus { .pagination > .active > span:hover, .pagination > .active > a:focus, .pagination > .active > span:focus { - z-index: 2; + z-index: 3; color: #fff; cursor: default; background-color: #337ab7; @@ -5024,6 +4976,8 @@ a.badge:focus { } .container .jumbotron, .container-fluid .jumbotron { + padding-right: 15px; + padding-left: 15px; border-radius: 6px; } .jumbotron .container { @@ -5978,7 +5932,6 @@ button.close { opacity: .5; } .modal-header { - min-height: 16.42857143px; padding: 15px; border-bottom: 1px solid #e5e5e5; } @@ -6371,6 +6324,7 @@ button.close { color: #fff; text-align: center; text-shadow: 0 1px 2px rgba(0, 0, 0, .6); + background-color: rgba(0, 0, 0, 0); filter: alpha(opacity=50); opacity: .5; } @@ -6484,16 +6438,16 @@ button.close { .carousel-control .icon-next { width: 30px; height: 30px; - margin-top: -15px; + margin-top: -10px; font-size: 30px; } .carousel-control .glyphicon-chevron-left, .carousel-control .icon-prev { - margin-left: -15px; + margin-left: -10px; } .carousel-control .glyphicon-chevron-right, .carousel-control .icon-next { - margin-right: -15px; + margin-right: -10px; } .carousel-caption { right: 20%; @@ -6532,6 +6486,8 @@ button.close { .pager:after, .panel-body:before, .panel-body:after, +.modal-header:before, +.modal-header:after, .modal-footer:before, .modal-footer:after { display: table; @@ -6551,6 +6507,7 @@ button.close { .navbar-collapse:after, .pager:after, .panel-body:after, +.modal-header:after, .modal-footer:after { clear: both; } diff --git a/WebRoot/css/menu-css.css b/WebRoot/css/menu-css.css new file mode 100644 index 0000000..aa3c84c --- /dev/null +++ b/WebRoot/css/menu-css.css @@ -0,0 +1,55 @@ +@charset "utf-8"; +.menu ul li { + display:block; + width:311px; + padding-top:2px; + margin-bottom:5px; + background: url(../images/zakladka.png) top left no-repeat; + list-style:none; + overflow:visible; +} +.menu ul li a { + display:block; + height:34px; width:273px; + margin-top:0px; + padding-top:10px; + padding-left:35px; + font-size:14px; + color:#82846f; + outline:none; +} +.menu ul li .active { + background:url(../images/on.png) top right no-repeat; +} + +.menu ul li .inactive { + background:url(../images/off.png) top right no-repeat; +} +.menu ul li ul { + display:none; + margin-top:-4px; + margin-bottom:20px; +} +.menu ul li ul li ul { + margin-bottom:5px; +} +.menu ul li ul li { + display:block; + background:none; + font-size:12px; + list-style:circle; + color:#8f9d4c; + margin-bottom:0px; + margin-top:0px; + padding-top:0px; + padding-bottom:0px; + padding-left:1px; + margin-left:35px; +} +.menu ul li ul li a { + background:none; + font-size:12px; + height:15px; + color:#8f9d4c; + padding-left:0px; +} \ No newline at end of file diff --git a/WebRoot/detail.jsp b/WebRoot/detail.jsp index 4fc1f92..8275853 100644 --- a/WebRoot/detail.jsp +++ b/WebRoot/detail.jsp @@ -9,14 +9,30 @@ - 帖子详情 +帖子详情 + @@ -29,6 +45,12 @@ Object user0 = session.getAttribute("actualuser"); /* out.println("欢迎"+user0);//输出当前session用户 */ %> + <% + String k1 = request.getQueryString();//得到ID的值(id=数字). + String re = "\\D+"; //正则表达式 + String result = k1.replaceAll(re, ""); //找到不是数字的字符,用""替代 + + %> <%@ include file="module/top.jsp"%>
@@ -39,47 +61,77 @@

帖子详情

-
+ -
- <% - String id = request.getParameter("id"); - Connection con; - Statement sql; - ResultSet rs; - String content = ""; - try { - Class.forName("com.mysql.jdbc.Driver"); - } catch (ClassNotFoundException e) { - out.print("驱动异常"); - } - con = DriverManager.getConnection("jdbc:mysql://localhost/db_bbs?useUnicode=true&characterEncoding=utf-8", - "root", ""); - sql = con.createStatement(); - String send = null; - content = "select subject,content,time from send where id = '" + request.getParameter("id") + "'"; - rs = sql.executeQuery(content); - try { + + <% + String id = request.getParameter("id"); + String username = ""; + Connection con; + Statement sql; + ResultSet rs; + String content = ""; + try { + Class.forName("com.mysql.jdbc.Driver"); + } catch (ClassNotFoundException e) { + out.print("驱动异常"); + } + con = DriverManager.getConnection("jdbc:mysql://localhost/db_bbs?useUnicode=true&characterEncoding=utf-8", + "root", ""); + sql = con.createStatement(); + String send = null; + content = "select subject,content,time,flag,username from send where id = '" + request.getParameter("id") + + "'"; + rs = sql.executeQuery(content); + while (rs.next()) { - %> - - + %> + <% + if (rs.getInt("flag") == 0) { + %> + + <% + } else { + %> + + <% + } + %> +
-
+

- 主题: <%=rs.getString("subject")%> -

-
- <%=rs.getDate("time")%> <%=rs.getTime("time")%> + <% + if (rs.getInt("flag") == 1) { + %> + 主题: <%=rs.getString("subject")%> + <% + } else { + %> + + 主题: ><%=rs.getString("subject")%> + + <% + } + %> + +
-
@@ -87,19 +139,25 @@

内容

<%=rs.getString("content")%> +
+ <%=rs.getString("username")%> <%=rs.getDate("time")%> <%=rs.getTime("time")%> +
<% - } - } catch (Exception e) { } sql.close(); rs.close(); con.close(); %> + + + +

评论信息

<% + int floor = 1; Connection comcon; Statement comsql; ResultSet comrs; @@ -111,23 +169,24 @@ comcon = DriverManager.getConnection("jdbc:mysql://localhost/db_bbs", "root", ""); comsql = comcon.createStatement(); String comment = null; - comment = "select comment,time from comment where subid = (select id from send where id ='" + id + "')"; + comment = "select commentid,comment,time,username from comment where subid = (select id from send where id ='" + + id + "')"; comrs = comsql.executeQuery(comment); try { while (comrs.next()) { %>
- + " + role="button"> <%=comrs.getString("comment")%> +
- <%=comrs.getDate("time")%> <%=comrs.getTime("time")%> + <%=floor++%>L <%=comrs.getString("username")%> <%=comrs.getDate("time")%> <%=comrs.getTime("time")%>
- - -
@@ -140,21 +199,19 @@ comsql.close(); comrs.close(); comcon.close(); - String k1 = request.getQueryString();//得到ID的值(id=数字). - String re = "\\D+"; - String result = k1.replaceAll(re, ""); //找到不是数字的字符,用""替代 %>




-
+ >

评论

+ type="submit" value="提交">
@@ -166,32 +223,34 @@
<%@ include file="module/footer.jsp"%>
+
+
- - - - - + + + + + - - - + + + - - - + + + diff --git a/WebRoot/forum/css/style.css b/WebRoot/forum/css/style.css index 64fb72a..95ee739 100644 --- a/WebRoot/forum/css/style.css +++ b/WebRoot/forum/css/style.css @@ -46,6 +46,11 @@ h3, h4, h5 { .createNew{ margin-top: 15px; } +.deleteTitle{ + margin-right: 15px; + margin-top: 5px; + margin-bottom: 5px; +} body:not (.fixed-sidebar ):not (.canvas-menu ).mini-navbar .nav li:hover>.nav-second-level, .mini-navbar .nav li:focus>.nav-second-level { display: block; diff --git a/WebRoot/forum/deleteComment.jsp b/WebRoot/forum/deleteComment.jsp new file mode 100644 index 0000000..6dd729a --- /dev/null +++ b/WebRoot/forum/deleteComment.jsp @@ -0,0 +1,45 @@ +<%@ page language="java" import="java.util.*,java.sql.*" pageEncoding="UTF-8"%> +<% +String path = request.getContextPath(); +String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; +%> + + + + + + 删除评论 + + + + + + + + + + + <% + String k1 = request.getQueryString();//得到ID的值(id=数字). + String re = "\\D+"; //正则表达式 + String result = k1.replaceAll(re, ""); //找到不是数字的字符,用""替代 + + Connection con;Statement sql; + try{Class.forName("com.mysql.jdbc.Driver"); } catch(ClassNotFoundException e){out.print("驱动异常");} + try{con=DriverManager.getConnection("jdbc:mysql://localhost/db_bbs?useUnicode=true&characterEncoding=utf-8","root",""); + sql=con.createStatement(); + String text="delete from comment where commentid = '"+result+"'" ; + sql.executeUpdate(text); + sql.close(); + con.close(); + out.print("成功删除评论"); + }catch(SQLException event){out.print("删除评论失败");} + + + + %> + + + diff --git a/WebRoot/forum/deletesend.jsp b/WebRoot/forum/deletesend.jsp new file mode 100644 index 0000000..546ae98 --- /dev/null +++ b/WebRoot/forum/deletesend.jsp @@ -0,0 +1,46 @@ +<%@ page language="java" import="java.util.*,java.sql.*" pageEncoding="UTF-8"%> +<% +String path = request.getContextPath(); +String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; +%> + + + + + + 删除帖子 + + + + + + + + + + + <% + String s[] = request.getParameterValues("chk"); + Connection con;Statement sql;ResultSet rs; + try{Class.forName("com.mysql.jdbc.Driver"); } catch(ClassNotFoundException e){out.print("驱动异常");} + try{con=DriverManager.getConnection("jdbc:mysql://localhost/db_bbs?useUnicode=true&characterEncoding=utf-8","root",""); + sql=con.createStatement(); + if(s!=null){ + for(int i=0;i + + + diff --git a/WebRoot/forum/send.jsp b/WebRoot/forum/send.jsp index e853e5a..ea0c85d 100644 --- a/WebRoot/forum/send.jsp +++ b/WebRoot/forum/send.jsp @@ -1,5 +1,5 @@ <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> -<%@ page import="java.sql.*" %> +<%@ page import="java.sql.*"%> <%-- <%! public String codeString(String s) { String str=s; @@ -12,24 +12,40 @@ - + -<% - request.setCharacterEncoding("utf-8"); - String k2 = request.getParameter("subject"); - String k3 = request.getParameter("content"); - Connection con;Statement sql;ResultSet rs; - try{Class.forName("com.mysql.jdbc.Driver"); } catch(ClassNotFoundException e){out.print("驱动异常");} - try{con=DriverManager.getConnection("jdbc:mysql://localhost/db_bbs?useUnicode=true&characterEncoding=utf-8","root",""); - sql=con.createStatement(); - String text="insert into send(subject,content,time) values('"+k2+"','"+k3+"',now())"; - sql.executeUpdate(text); - sql.close(); - con.close(); - out.print("成功发表帖子"); - }catch(SQLException event){out.print("数据更新异常");} - -%> + <% + /* String URL = "sendForum.jsp"; + String referer = response.getHeader("Referer"); + if (referer == null || !referer.startsWith(URL)) { + response.sendRedirect(URL); + return; + } */ + request.setCharacterEncoding("utf-8"); + String k2 = request.getParameter("subject"); + String k3 = request.getParameter("content"); + String k4 = request.getParameter("username"); + Connection con; + Statement sql; + ResultSet rs; + try { + Class.forName("com.mysql.jdbc.Driver"); + } catch (ClassNotFoundException e) { + out.print("驱动异常"); + } + try { + con = DriverManager.getConnection( + "jdbc:mysql://localhost/db_bbs?useUnicode=true&characterEncoding=utf-8", "root", ""); + sql = con.createStatement(); + String text = "insert into send(subject,content,time,username) values('" + k2 + "','" + k3 + "',now(),'" + k4 + "')"; + sql.executeUpdate(text); + sql.close(); + con.close(); + out.print("成功发表帖子"); + } catch (SQLException event) { + out.print("数据更新异常"); + } + %> \ No newline at end of file diff --git a/WebRoot/forum/sendComment.jsp b/WebRoot/forum/sendComment.jsp index 3379a13..4b4f45d 100644 --- a/WebRoot/forum/sendComment.jsp +++ b/WebRoot/forum/sendComment.jsp @@ -28,14 +28,19 @@ <% + String referer=response.getHeader("Referer"); + if(referer==null||!referer.startsWith("detail.jsp")){ + response.sendRedirect("../index.jsp"); + } request.setCharacterEncoding("utf-8"); String k5 = request.getParameter("comment"); String k6 = request.getParameter("subid"); + String k7 = request.getParameter("username"); Connection con; Statement sql;ResultSet rs; try{Class.forName("com.mysql.jdbc.Driver"); } catch(ClassNotFoundException e){out.print("驱动异常");} try{con=DriverManager.getConnection("jdbc:mysql://localhost/db_bbs?useUnicode=true&characterEncoding=utf-8","root",""); sql=con.createStatement(); - String text="insert into comment(subid,comment,time) values('"+k6+"','"+k5+"',now())"; + String text="insert into comment(subid,comment,time,username) values('"+k6+"','"+k5+"',now(),'"+k7+"')"; sql.executeUpdate(text); sql.close(); diff --git a/WebRoot/forum/submitDown.jsp b/WebRoot/forum/submitDown.jsp new file mode 100644 index 0000000..0b95242 --- /dev/null +++ b/WebRoot/forum/submitDown.jsp @@ -0,0 +1,39 @@ +<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> +<%@ page import="java.sql.*" %> +<%! + public String codeString(String s) + { String str=s; + try{byte b[]=str.getBytes("ISO-8859-1"); + str=new String(b); return str; + } catch(Exception e) { return str; } +} +%> + + + + + + +<% + /* String referer=response.getHeader("Referer"); + if(referer==null||!referer.startsWith("detail.jsp")){ + response.sendRedirect("../index.jsp"); + return; + } */ + String k1 = request.getQueryString();//得到ID的值(id=数字). + String re = "\\D+"; //正则表达式 + String result = k1.replaceAll(re, ""); //找到不是数字的字符,用""替代 + Connection con;Statement sql; + try{Class.forName("com.mysql.jdbc.Driver"); } catch(ClassNotFoundException e){out.print("驱动异常");} + try{con=DriverManager.getConnection("jdbc:mysql://localhost/db_bbs?useUnicode=true&characterEncoding=utf-8","root",""); + sql=con.createStatement(); + String text="update send set flag = 0 where id = '"+result+"'"; + sql.executeUpdate(text); + sql.close(); + con.close(); + out.print("成功取消置顶"); + }catch(SQLException event){out.print("取消置顶失败");} + +%> + + \ No newline at end of file diff --git a/WebRoot/forum/submitTop.jsp b/WebRoot/forum/submitTop.jsp new file mode 100644 index 0000000..3900e21 --- /dev/null +++ b/WebRoot/forum/submitTop.jsp @@ -0,0 +1,33 @@ +<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> +<%@ page import="java.sql.*" %> + + + + + + + +<% + + /* String referer=response.getHeader("Referer"); //防止用户在地址栏上直接访问 + if(referer==null||!referer.startsWith("detail.jsp")){ + response.sendRedirect("../index.jsp"); + return; + } */ + String k1 = request.getQueryString();//得到ID的值(id=数字). + String re = "\\D+"; //正则表达式 + String result = k1.replaceAll(re, ""); //找到不是数字的字符,用""替代 + Connection con;Statement sql; + try{Class.forName("com.mysql.jdbc.Driver"); } catch(ClassNotFoundException e){out.print("驱动异常");} + try{con=DriverManager.getConnection("jdbc:mysql://localhost/db_bbs?useUnicode=true&characterEncoding=utf-8","root",""); + sql=con.createStatement(); + String text="update send set flag = 1 where id = '"+result+"'"; + sql.executeUpdate(text); + sql.close(); + con.close(); + out.print("成功置顶帖子"); + }catch(SQLException event){out.print("置顶帖子失败");} + +%> + + \ No newline at end of file diff --git a/WebRoot/index.jsp b/WebRoot/index.jsp index bb9df12..861dfd0 100644 --- a/WebRoot/index.jsp +++ b/WebRoot/index.jsp @@ -44,38 +44,44 @@

帖子列表

- - <% - Connection con; - Statement sql; - ResultSet rs; - int id = 0; - String subject = "", content = ""; - Date time = new Date(); - SimpleDateFormat sdf = new SimpleDateFormat(); - sdf.format(time); - try { - Class.forName("com.mysql.jdbc.Driver"); - } catch (ClassNotFoundException e) { - out.print("驱动异常"); - } - con = DriverManager.getConnection("jdbc:mysql://localhost/db_bbs?useUnicode=true&characterEncoding=utf-8", - "root", ""); - sql = con.createStatement(); - String send = null; - content = "select id,subject,time from send"; - rs = sql.executeQuery(content); - while (rs.next()) { - id = rs.getInt("id"); - subject = rs.getString("subject"); - %> +
+ + <% + Connection con; + Statement sql; + ResultSet rs; + int id = 0; + String regex1 = "<(?!img).*?>"; + /* String username = "admin"; */ + String subject = "", content = "", username = ""; + Date time = new Date(); + SimpleDateFormat sdf = new SimpleDateFormat(); + sdf.format(time); + try { + Class.forName("com.mysql.jdbc.Driver"); + } catch (ClassNotFoundException e) { + out.print("驱动异常"); + } + con = DriverManager.getConnection("jdbc:mysql://localhost/db_bbs?useUnicode=true&characterEncoding=utf-8", + "root", ""); + sql = con.createStatement(); + String send = null; + content = "select id,subject,username,time,flag from send order by flag desc,id"; + rs = sql.executeQuery(content); + while (rs.next()) { + id = rs.getInt("id"); + subject = rs.getString("subject"); + username = rs.getString("username"); + String str = String.valueOf(id); + %> @@ -83,53 +89,97 @@ +
- - - - - - - +
<%=subject%><%=rs.getDate("time")%> <%=rs.getTime("time")%>
+ + + + <% + if (rs.getInt("flag") == 1 && subject.matches(regex1)) { + //置顶且匹配 + %> - -
>
- <% - } - sql.close(); - rs.close(); - con.close(); - %> + + + <% + } + if (rs.getInt("flag") == 0 && !(subject.matches(regex1))) { + //不置顶不匹配 + %> + <%=subject%> + + <% + } + if (rs.getInt("flag") == 1 && !(subject.matches(regex1))) { + //置顶但不匹配 + %> + + + + + <% + } + if (rs.getInt("flag") == 0 && subject.matches(regex1)) { + //不置顶但匹配 + %> + + + <% + } + %> + <%=username%>  <%=rs.getDate("time")%> <%=rs.getTime("time")%> + + + + +
+ <% + } + sql.close(); + rs.close(); + con.close(); + %> + +
+
- <%@ include file="module/footer.jsp"%> + + + <%@ include file="module/footer.jsp"%> + - - - - - + + + + + - - - + + + - - - + + + diff --git a/WebRoot/js/menu_min.js b/WebRoot/js/menu_min.js new file mode 100644 index 0000000..904ec81 --- /dev/null +++ b/WebRoot/js/menu_min.js @@ -0,0 +1,51 @@ +(function($) { + $.fn.menu = function(b) { + var c, + item, + httpAdress; + b = jQuery.extend({ + Speed: 220, + autostart: 1, + autohide: 1 + }, + b); + c = $(this); + item = c.children("ul").parent("li").children("a"); + httpAdress = window.location; + item.addClass("inactive"); + function _item() { + var a = $(this); + if (b.autohide) { + a.parent().parent().find(".active").parent("li").children("ul").slideUp(b.Speed / 1.2, + function() { + $(this).parent("li").children("a").removeAttr("class"); + $(this).parent("li").children("a").attr("class", "inactive") + }) + } + if (a.attr("class") == "inactive") { + a.parent("li").children("ul").slideDown(b.Speed, + function() { + a.removeAttr("class"); + a.addClass("active") + }) + } + if (a.attr("class") == "active") { + a.removeAttr("class"); + a.addClass("inactive"); + a.parent("li").children("ul").slideUp(b.Speed) + } + } + item.unbind('click').click(_item); + if (b.autostart) { + c.children("a").each(function() { + if (this.href == httpAdress) { + $(this).parent("li").parent("ul").slideDown(b.Speed, + function() { + $(this).parent("li").children(".inactive").removeAttr("class"); + $(this).parent("li").children("a").addClass("active") + }) + } + }) + } + } +})(jQuery); \ No newline at end of file diff --git a/WebRoot/login.jsp b/WebRoot/login.jsp deleted file mode 100644 index a2dd2d7..0000000 --- a/WebRoot/login.jsp +++ /dev/null @@ -1,59 +0,0 @@ -<%@ page language="java" import="java.sql.*" contentType="text/html;charset=utf-8"%> -<% -String path = request.getContextPath(); -String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; -%> - - - - - My JSP 'check.jsp' starting page - - - - - - - - -<% - request.setCharacterEncoding("utf-8"); - String users=request.getParameter("inputUser"); - String pass=request.getParameter("inputPassword"); - boolean flag=false; - PreparedStatement sql=null; - ResultSet rs=null; - Connection conn=null; -%> - -<% - String driver = "com.mysql.jdbc.Driver"; - String url="jdbc:mysql://localhost:3306/db_school"; - String use = "root"; - String password = ""; - Class.forName(driver); - conn= DriverManager.getConnection(url,use,password); - sql =conn.prepareStatement("select * from user where userName=? and password=?"); - sql.setString(1,users); - sql.setString(2,pass); - rs=sql.executeQuery(); - if (rs.next()) { - flag=true; - } - rs.close(); - sql.close(); - conn.close(); - %> - -<% if (flag==true){ %> - -<%} -else -if (flag==false){ -%> - -<%} %> - - \ No newline at end of file diff --git a/WebRoot/login_fail.jsp b/WebRoot/login_fail.jsp deleted file mode 100644 index bb5cb5d..0000000 --- a/WebRoot/login_fail.jsp +++ /dev/null @@ -1,29 +0,0 @@ -<%@ page language="java" import="java.sql.*" contentType="text/html;charset=utf-8"%> -<% -String path = request.getContextPath(); -String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; -%> - - - - - - - 登录失败 - - - - - - - - - - - - <% out.println("登录失败,5秒后自动跳转回登录页面");%> - <% response.setHeader("refresh","5;url=index.html");%> - - \ No newline at end of file diff --git a/WebRoot/login_show.jsp b/WebRoot/login_show.jsp deleted file mode 100644 index 21ec0fd..0000000 --- a/WebRoot/login_show.jsp +++ /dev/null @@ -1,27 +0,0 @@ -<%@ page language="java" import="java.util.*" contentType="text/html;charset=utf-8"%> -<% -String path = request.getContextPath(); -String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; -%> - - - - - - 登录成功 - - - - - - - - - - - 登录成功.
-<% response.setHeader("refresh","0;url=manage.html");%> - - \ No newline at end of file diff --git a/WebRoot/mainframe.html b/WebRoot/mainframe.html deleted file mode 100644 index 8c49794..0000000 --- a/WebRoot/mainframe.html +++ /dev/null @@ -1,16 +0,0 @@ - - - - -ޱĵ - - - - - diff --git a/WebRoot/mainframe.jsp b/WebRoot/mainframe.jsp index 8eb274a..d35d39d 100644 --- a/WebRoot/mainframe.jsp +++ b/WebRoot/mainframe.jsp @@ -82,9 +82,9 @@ String str_date2 = currentTime.toString(); //将Date型日期时间转换成字 <%-- <%=counter %> --%>
- -->

欢迎访问

15信管2班

diff --git a/WebRoot/manage.html b/WebRoot/manage.html deleted file mode 100644 index 80b50b6..0000000 --- a/WebRoot/manage.html +++ /dev/null @@ -1,14 +0,0 @@ - - - - -ޱĵ - - - - - - -<body> -</body> - diff --git a/WebRoot/message.jsp b/WebRoot/message.jsp new file mode 100644 index 0000000..38e70ef --- /dev/null +++ b/WebRoot/message.jsp @@ -0,0 +1,12 @@ +<%@ page language="java" pageEncoding="UTF-8"%> + + + + 消息提示 + + + + ${message} + <%-- <% response.setHeader("refresh","1;url=../x2_resource.jsp");%> --%> + + \ No newline at end of file diff --git a/WebRoot/module/sidebar.jsp b/WebRoot/module/sidebar.jsp index 5996599..238f475 100644 --- a/WebRoot/module/sidebar.jsp +++ b/WebRoot/module/sidebar.jsp @@ -45,6 +45,8 @@

管理员档案

  • 添加管理员(current)
  • +
  • 添加档案(current)
  • 查看管理员
  • 展示管理员
  • 修改管理员
  • diff --git a/WebRoot/module/sidebar_pull.jsp b/WebRoot/module/sidebar_pull.jsp new file mode 100644 index 0000000..238f475 --- /dev/null +++ b/WebRoot/module/sidebar_pull.jsp @@ -0,0 +1,74 @@ +<%@ page language="java" contentType="text/html; charset=UTF-8" + pageEncoding="UTF-8"%> + + + + + + +test + + + + + + + + + + + + \ No newline at end of file diff --git a/WebRoot/send.html b/WebRoot/send.html deleted file mode 100644 index 928172a..0000000 --- a/WebRoot/send.html +++ /dev/null @@ -1,100 +0,0 @@ - - - - - - - - - -发表帖子 - - - - - - - - - - - - -
    -
    -
    -

    发表帖子

    -
    - -
    - - - -
    -
    - - - - -
    - - - - -
    - -
    -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/WebRoot/send.jsp b/WebRoot/send.jsp index e468f9a..82f7590 100644 --- a/WebRoot/send.jsp +++ b/WebRoot/send.jsp @@ -1,4 +1,5 @@ -<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> +<%@ page language="java" contentType="text/html; charset=UTF-8" + pageEncoding="UTF-8"%> @@ -8,7 +9,7 @@ - 发表帖子 +发表帖子 @@ -26,7 +27,7 @@ <% if (session.getAttribute("actualuser") == null) { out.println( - ""); + ""); return; } Object user0 = session.getAttribute("actualuser"); @@ -42,32 +43,33 @@

    发表帖子

    -
    + > +
    -
    -
    + + + + +
    + + +
    - - -
    - - - - -
    - -
    + + + +
    +
    +
    - - <%@ include file="module/footer.jsp"%> - + <%@ include file="module/footer.jsp"%> @@ -80,7 +82,7 @@ - + @@ -116,4 +118,4 @@ - \ No newline at end of file + diff --git a/WebRoot/sendForum.jsp b/WebRoot/sendForum.jsp new file mode 100644 index 0000000..10a4848 --- /dev/null +++ b/WebRoot/sendForum.jsp @@ -0,0 +1,137 @@ +<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> + + + + + + + + + +发表帖子 + + + + + + + + + + + + + <% + if (session.getAttribute("actualuser") == null) { + out.println( + ""); + return; + } + Object user0 = session.getAttribute("actualuser"); + /* out.println("欢迎"+user0);//输出当前session用户 */ + %> + <%@ include file="module/top.jsp"%> +
    +
    + <%@ include file="module/sidebar.jsp"%> + +
    +
    +
    +

    发表帖子

    +
    + +
    +
    +
    +
    + + +
    + + + + +
    +
    +
    +
    +
    +
    + <%@ include file="module/footer.jsp"%> +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/WebRoot/signin_insert.jsp b/WebRoot/signin_insert.jsp deleted file mode 100644 index 46d652c..0000000 --- a/WebRoot/signin_insert.jsp +++ /dev/null @@ -1,51 +0,0 @@ -<%@ page language="java" import="java.sql.*" contentType="text/html;charset=utf-8"%> -<% -String path = request.getContextPath(); -String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; -%> - - - - - - - 检验注册页面 - - - - - - - - - - -
    - <% - request.setCharacterEncoding("utf-8"); - String users=request.getParameter("inputUser"); - String pass=request.getParameter("Password2"); - String email=request.getParameter("Email"); - String PhoneNumber=request.getParameter("PhoneNumber"); - %> - <% - String driver = "com.mysql.jdbc.Driver"; - String url="jdbc:mysql://localhost:3306/db_school"; - String use = "root"; - String password = ""; - Class.forName(driver); - Connection conn= DriverManager.getConnection(url,use,password); - PreparedStatement sql =conn.prepareStatement("insert into user(userName,password,Email,phoneNum)values(?,?,?,?)"); - sql.setString(1,users); - sql.setString(2,pass); - sql.setString(3,email); - sql.setString(4,PhoneNumber); - int rtn=sql.executeUpdate(); - sql.close(); - conn.close(); - %> - <% response.setHeader("refresh","0;url=signin_show.jsp");%> - - \ No newline at end of file diff --git a/WebRoot/top.html b/WebRoot/top.html deleted file mode 100644 index e7ea70b..0000000 --- a/WebRoot/top.html +++ /dev/null @@ -1,62 +0,0 @@ - - - - - - -学生管理 - - - - - - - - - - - - \ No newline at end of file diff --git a/WebRoot/upload.jsp b/WebRoot/upload.jsp new file mode 100644 index 0000000..ba581c9 --- /dev/null +++ b/WebRoot/upload.jsp @@ -0,0 +1,16 @@ +<%@ page language="java" pageEncoding="UTF-8"%> + + + + 文件上传 + + + +
    + 上传用户:
    + 上传文件1:
    + 上传文件2:
    + +
    + + \ No newline at end of file diff --git a/WebRoot/x2_resource.jsp b/WebRoot/x2_resource.jsp index e1241c9..60a2bc4 100644 --- a/WebRoot/x2_resource.jsp +++ b/WebRoot/x2_resource.jsp @@ -25,7 +25,7 @@ <%@ include file="/module/top.jsp"%>
    <% - String counter = null; + String counter = null; if (session.getAttribute("actualuser") == null) { out.println(""); return; @@ -58,10 +58,10 @@ String password = ""; Class.forName(driverClass); try { - ResultSet rs = null; - Connection conn = null; - PreparedStatement sql = null; - + ResultSet rs = null; + Connection conn = null; + PreparedStatement sql = null; + conn = DriverManager.getConnection(url, user, password); Statement stmt = conn.createStatement(); sql = conn.prepareStatement("select * from x2_resourse"); @@ -72,16 +72,17 @@ <%=rs.getString("resName")%> <%=rs.getString("size")%> <%=rs.getString("upLoadTime")%> - <%=rs.getString("downLoadTimes")%> - "> + <%=rs.getString("upLoaduser")%> + "> <% } - sql.close(); - rs.close(); - conn.close(); - stmt.close(); + sql.close(); + rs.close(); + conn.close(); + stmt.close(); } catch (Exception ex) { ex.printStackTrace(); } @@ -93,6 +94,24 @@
    +
    +
    +

    上传文件

    +
    +
    +
    + + +
    + 上传文件:
    + +
    +
    +
    +
    diff --git a/src/com/wgh/MySqlconn.java b/src/com/wgh/MySqlconn.java new file mode 100644 index 0000000..e4dac8f --- /dev/null +++ b/src/com/wgh/MySqlconn.java @@ -0,0 +1,7 @@ +package com.wgh; + +public class MySqlconn { + static String driverClass = "com.mysql.jdbc.Driver"; + static String user = "root"; + static String password = ""; +} diff --git a/src/com/wgh/UserForm.java b/src/com/wgh/UserForm.java index 56dd888..55535f9 100644 --- a/src/com/wgh/UserForm.java +++ b/src/com/wgh/UserForm.java @@ -3,4 +3,4 @@ package com.wgh; public class UserForm { public String username; -} +} \ No newline at end of file diff --git a/src/me/gacl/web/controller/DownLoadServlet.java b/src/me/gacl/web/controller/DownLoadServlet.java new file mode 100644 index 0000000..f60d003 --- /dev/null +++ b/src/me/gacl/web/controller/DownLoadServlet.java @@ -0,0 +1,80 @@ +package me.gacl.web.controller; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.net.URLEncoder; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +public class DownLoadServlet extends HttpServlet { + + + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + //õҪصļ + String fileName = request.getParameter("filename"); //23239283-92489-.avi + fileName = new String(fileName.getBytes("iso8859-1"),"UTF-8"); + //ϴļDZ/WEB-INF/uploadĿ¼µĿ¼ + String fileSaveRootPath=this.getServletContext().getRealPath("/WEB-INF/upload"); + //ͨļҳļĿ¼ + String path = findFileSavePathByFileName(fileName,fileSaveRootPath); + //õҪصļ + File file = new File(path + "\\" + fileName); + //ļ + if(!file.exists()){ + request.setAttribute("message", "ҪصԴѱɾ"); + request.getRequestDispatcher("/message.jsp").forward(request, response); + return; + } + //ļ + String realname = fileName.substring(fileName.indexOf("_")+1); + //Ӧͷظļ + response.setHeader("content-disposition", "attachment;filename=" + URLEncoder.encode(realname, "UTF-8")); + //ȡҪصļ浽ļ + FileInputStream in = new FileInputStream(path + "\\" + fileName); + // + OutputStream out = response.getOutputStream(); + // + byte buffer[] = new byte[1024]; + int len = 0; + //ѭеݶȡ + while((len=in.read(buffer))>0){ + //ݵʵļ + out.write(buffer, 0, len); + } + //رļ + in.close(); + //ر + out.close(); + } + + /** + * @Method: findFileSavePathByFileName + * @Description: ͨļʹ洢ϴļĿ¼ҳҪصļ· + * @Anthor:° + * @param filename Ҫصļ + * @param saveRootPath ϴļĸĿ¼Ҳ/WEB-INF/uploadĿ¼ + * @return ҪصļĴ洢Ŀ¼ + */ + public String findFileSavePathByFileName(String filename,String saveRootPath){ + int hashcode = filename.hashCode(); + int dir1 = hashcode&0xf; //0--15 + int dir2 = (hashcode&0xf0)>>4; //0-15 + String dir = saveRootPath + "\\" + dir1 + "\\" + dir2; //upload\2\3 upload\3\5 + File file = new File(dir); + if(!file.exists()){ + //Ŀ¼ + file.mkdirs(); + } + return dir; + } + + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doGet(request, response); + } +} \ No newline at end of file diff --git a/src/me/gacl/web/controller/ListFileServlet.java b/src/me/gacl/web/controller/ListFileServlet.java new file mode 100644 index 0000000..a16e465 --- /dev/null +++ b/src/me/gacl/web/controller/ListFileServlet.java @@ -0,0 +1,67 @@ +package me.gacl.web.controller; + +import java.io.File; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** +* @ClassName: ListFileServlet +* @Description: гWebϵͳļ +* @author: ° +* @date: 2015-1-4 9:54:40 +* +*/ +public class ListFileServlet extends HttpServlet { + + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + //ȡϴļĿ¼ + String uploadFilePath = this.getServletContext().getRealPath("/WEB-INF/upload"); + //洢Ҫصļ + Map fileNameMap = new HashMap(); + //ݹfilepathĿ¼µļĿ¼ļļ洢map + listfile(new File(uploadFilePath),fileNameMap);//FileȿԴһļҲԴһĿ¼ + //MapϷ͵listfile.jspҳʾ + request.setAttribute("fileNameMap", fileNameMap); + request.getRequestDispatcher("/listfile.jsp").forward(request, response); + } + + /** + * @Method: listfile + * @Description: ݹָĿ¼µļ + * @Anthor:° + * @param file һļҲһļĿ¼ + * @param map 洢ļMap + */ + public void listfile(File file,Map map){ + //fileIJһļһĿ¼ + if(!file.isFile()){ + //гĿ¼µļĿ¼ + File files[] = file.listFiles(); + //files[] + for(File f : files){ + //ݹ + listfile(f,map); + } + }else{ + /** + * ļϴļuuid_ļʽȥģȥļuuid_ + file.getName().indexOf("_")ַеһγ"_"ַλãļڣ9349249849-88343-8344___.avi + ôfile.getName().substring(file.getName().indexOf("_")+1)֮ͿԵõ__.avi + */ + String realName = file.getName().substring(file.getName().indexOf("_")+1); + //file.getName()õļԭʼƣΨһģ˿ΪkeyrealNameǴƣпܻظ + map.put(file.getName(), realName); + } + } + + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doGet(request, response); + } +} \ No newline at end of file diff --git a/src/me/gacl/web/controller/UploadHandleServlet.java b/src/me/gacl/web/controller/UploadHandleServlet.java new file mode 100644 index 0000000..7953a08 --- /dev/null +++ b/src/me/gacl/web/controller/UploadHandleServlet.java @@ -0,0 +1,119 @@ +package me.gacl.web.controller; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.List; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import org.apache.commons.fileupload.FileItem; +import org.apache.commons.fileupload.disk.DiskFileItemFactory; +import org.apache.commons.fileupload.servlet.ServletFileUpload; +import org.omg.CORBA.PRIVATE_MEMBER; + +import java.sql.*; +public class UploadHandleServlet extends HttpServlet { + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + final String DBDRIVER = "com.mysql.jdbc.Driver"; + final String DBURL = "jdbc:mysql://localhost:3306/db_school?useUnicode=true&characterEncoding=utf-8"; + final String USER = "root"; + final String PASSWORD = ""; + boolean flag = false; + request.setCharacterEncoding("utf-8"); + String username = request.getParameter("username"); + //õϴļıĿ¼ϴļWEB-INFĿ¼£ֱӷʣ֤ϴļİȫ + String savePath = this.getServletContext().getRealPath("/WEB-INF/upload"); + File file = new File(savePath); + //жϴļıĿ¼Ƿ + if (!file.exists() && !file.isDirectory()) { + System.out.println(savePath+"Ŀ¼ڣҪ"); + //Ŀ¼ + file.mkdir(); + } + //Ϣʾ + String message = ""; + try{ + Class.forName(DBDRIVER); + Connection conn = DriverManager.getConnection(DBURL, USER, PASSWORD); + //ʹApacheļϴļϴ裺 + //1һDiskFileItemFactory + DiskFileItemFactory factory = new DiskFileItemFactory(); + //2һļϴ + ServletFileUpload upload = new ServletFileUpload(factory); + //ϴļ + upload.setHeaderEncoding("UTF-8"); + //3жύǷϴ + if(!ServletFileUpload.isMultipartContent(request)){ + //մͳʽȡ + return; + } + //4ʹServletFileUploadϴݣصһListϣÿһFileItemӦһForm + List list = upload.parseRequest(request); + for(FileItem item : list){ + //fileitemзװͨ + if(item.isFormField()){ + String name = item.getFieldName(); + //ͨݵ + String value = item.getString("UTF-8"); + //value = new String(value.getBytes("iso8859-1"),"UTF-8"); + System.out.println(name + "=" + value); + }else{//fileitemзװϴļ + //õϴļƣ + String filename = item.getName(); + PreparedStatement sql = conn + .prepareStatement("insert into x2_resourse_upload(resName,upLoadTime,upLoaduser)values(?,now(),?)"); + sql.setString(1, filename); + sql.setString(2, username); + System.out.println(filename); + if(filename==null || filename.trim().equals("")){ + continue; + } + //ע⣺ͬύļDzһģЩύļǴ·ģ磺 c:\a\b\1.txtЩֻǵļ磺1.txt + //ȡϴļļ·ֻ֣ļ + filename = filename.substring(filename.lastIndexOf("\\")+1); + //ȡitemеϴļ + InputStream in = item.getInputStream(); + //һļ + FileOutputStream out = new FileOutputStream(savePath + "\\" + filename); + //һ + byte buffer[] = new byte[1024]; + //жеǷѾıʶ + int len = 0; + //ѭ뵽У(len=in.read(buffer))>0ͱʾin滹 + while((len=in.read(buffer))>0){ + //ʹFileOutputStreamд뵽ָĿ¼(savePath + "\\" + filename) + out.write(buffer, 0, len); + } + //ر + in.close(); + //ر + out.close(); + //ɾļϴʱɵʱļ + item.delete(); + message = "ļϴɹ"+username; + sql.close(); + conn.close(); + } + + } + + }catch (Exception e) { + message= "ļϴʧܣ"; + e.printStackTrace(); + + } + + request.setAttribute("message",message); + request.getRequestDispatcher("/message.jsp").forward(request, response); + } + + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + doGet(request, response); + } +} \ No newline at end of file