diff --git a/readme.txt b/readme.txt index e51b461ff376e73aff11707c425aa1e9bd95543a..75a6bf32194fa58fc80eb4a6ce27d518eb749e84 100644 --- a/readme.txt +++ b/readme.txt @@ -10,4 +10,7 @@ eclipce 2022 tomcat9.0.94 mysql 5.7.44 1 学费管理(查看/设置,学费未交统计,学费已交统计) 2.学生 修改我的信息,查看我的学费信息 -交学费,修改密码,选择缴费项目 \ No newline at end of file +交学费,修改密码,选择缴费项目 + +左侧功能栏使用iframe 嵌套页面实现(iframe 嵌套页面是一个简单且有效的方式,能够在不刷新整个页面的情况下更新内容,同时保持页面的导航栏和其他固定部分不变) +因为部分功能涉及到对数据的修改,页面的刷新,再用AJAX会导致导航栏不显示 \ No newline at end of file diff --git a/src/main/java/com/tjl/dao/StudentDAO.java b/src/main/java/com/tjl/dao/StudentDAO.java index ee2be4e28ef3a3dcccf50c7586b71e1acc4598a8..45c61c09b01d9fbc4a649d34301729aca410a94d 100644 --- a/src/main/java/com/tjl/dao/StudentDAO.java +++ b/src/main/java/com/tjl/dao/StudentDAO.java @@ -19,20 +19,20 @@ public class StudentDAO { Connection conn = null; PreparedStatement pstmt = null; ResultSet rs = null; - + try { Properties properties = JDBCUtil.loadProperties(); conn = JDBCUtil.getConnection(properties); pstmt = conn.prepareStatement(SELECT_STUDENT_BY_SNAME); pstmt.setString(1, sname); rs = pstmt.executeQuery(); - + if (rs.next()) { student = new Student(); student.setId(rs.getInt("id")); student.setSname(rs.getString("sname")); student.setAge(rs.getInt("age")); - student.setGender(rs.getString("gender")); + student.setGender(rs.getString("gender")); // 直接存储“男”或“女” student.setInfoId(rs.getInt("infoId")); student.setEmail(rs.getString("email")); student.setPhone(rs.getString("phone")); @@ -42,9 +42,10 @@ public class StudentDAO { } finally { JDBCUtil.closeResources(rs, pstmt, conn); } - + return student; - } + } + public Info getInfoById(int id) { Info info = null; @@ -206,4 +207,50 @@ public class StudentDAO { } return studentId; } + + public String getPayPasswordBySname(String sname) { + String payPassword = null; + String sql = "SELECT paypassword FROM student WHERE sname = ?"; + Properties properties = null; + try { + properties = JDBCUtil.loadProperties(); + } catch (IOException e1) { + e1.printStackTrace(); + } + try (Connection conn = JDBCUtil.getConnection(properties); + PreparedStatement pstmt = conn.prepareStatement(sql)) { + pstmt.setString(1, sname); + ResultSet rs = pstmt.executeQuery(); + if (rs.next()) { + payPassword = rs.getString("paypassword"); + } + } catch (SQLException e) { + e.printStackTrace(); + } catch (ClassNotFoundException e1) { + e1.printStackTrace(); + } + return payPassword; + } + + public boolean updatePayPasswordBySname(String sname, String newPayPassword) { + String sql = "UPDATE student SET paypassword = ? WHERE sname = ?"; + Properties properties = null; + try { + properties = JDBCUtil.loadProperties(); + } catch (IOException e1) { + e1.printStackTrace(); + } + try (Connection conn = JDBCUtil.getConnection(properties); + PreparedStatement pstmt = conn.prepareStatement(sql)) { + pstmt.setString(1, newPayPassword); + pstmt.setString(2, sname); + int affectedRows = pstmt.executeUpdate(); + return affectedRows > 0; + } catch (SQLException e) { + e.printStackTrace(); + } catch (ClassNotFoundException e1) { + e1.printStackTrace(); + } + return false; + } } diff --git a/src/main/java/com/tjl/servlet/StudentChangeInfoServlet.java b/src/main/java/com/tjl/servlet/StudentChangeInfoServlet.java index 70835eea1201ecb0c2b239e396179fb986623f88..f1b13f889efc3c104f00ecff6d31dc622a8f912d 100644 --- a/src/main/java/com/tjl/servlet/StudentChangeInfoServlet.java +++ b/src/main/java/com/tjl/servlet/StudentChangeInfoServlet.java @@ -11,10 +11,16 @@ import java.io.IOException; @WebServlet("/studentchangelnfo") public class StudentChangeInfoServlet extends HttpServlet { + private StudentDAO studentDAO = new StudentDAO(); + @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + // 设置请求和响应的编码 + request.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding("UTF-8"); + response.setContentType("text/html;charset=UTF-8"); String uname = (String) request.getSession().getAttribute("uname"); if (uname != null) { Student student = studentDAO.getStudentBySname(uname); @@ -32,20 +38,24 @@ public class StudentChangeInfoServlet extends HttpServlet { @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + request.setCharacterEncoding("UTF-8"); String uname = (String) request.getSession().getAttribute("uname"); if (uname != null) { + // 获取修改的其他字段 int age = Integer.parseInt(request.getParameter("age")); - String gender = request.getParameter("gender"); String email = request.getParameter("email"); String phone = request.getParameter("phone"); - Student student = new Student(); + // 获取当前学生信息 + Student student = studentDAO.getStudentBySname(uname); + + // 更新学生信息,性别不需要修改 student.setAge(age); - student.setGender(gender); student.setEmail(email); student.setPhone(phone); - student.setSname(uname); // 不能修改姓名 - + + // 姓名不修改,直接从session中的uname获取 + boolean updated = studentDAO.updateStudentInfo(student); if (updated) { @@ -57,4 +67,5 @@ public class StudentChangeInfoServlet extends HttpServlet { response.sendRedirect(request.getContextPath() + "/login.jsp"); } } + } \ No newline at end of file diff --git a/src/main/java/com/tjl/servlet/StudentChangePayPasswordServlet.java b/src/main/java/com/tjl/servlet/StudentChangePayPasswordServlet.java index ac4bfa335c127d36bcf60bc0fdb7e6fdc847a613..719d8d4520276eae6842b1a64dcc3d69f20d9d3e 100644 --- a/src/main/java/com/tjl/servlet/StudentChangePayPasswordServlet.java +++ b/src/main/java/com/tjl/servlet/StudentChangePayPasswordServlet.java @@ -34,42 +34,45 @@ public class StudentChangePayPasswordServlet extends HttpServlet { protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String uname = (String) request.getSession().getAttribute("uname"); if (uname != null) { - Student student = studentDAO.getStudentBySname(uname); - if (student != null) { - String newPassword1 = request.getParameter("newPassword1"); - String newPassword2 = request.getParameter("newPassword2"); + String oldPassword = request.getParameter("oldPassword"); + String newPassword1 = request.getParameter("newPassword1"); + String newPassword2 = request.getParameter("newPassword2"); - // 检查密码是否为空 - if (newPassword1 == null || newPassword2 == null) { - request.setAttribute("error", "密码不能为空"); - } - // 检查两次密码是否一致 - else if (!newPassword1.equals(newPassword2)) { - request.setAttribute("error", "两次密码输入不同"); - } - // 检查密码是否为数字 - else if (!newPassword1.matches("\\d+")) { - request.setAttribute("error", "必须输入数字"); - } - // 检查密码是否为6位 - else if (newPassword1.length() != 6) { - request.setAttribute("error", "密码必须为6位数字"); - } - // 如果所有检查都通过,则更新密码 - else { - student.setPaypassword(Integer.parseInt(newPassword1)); - boolean updated = studentDAO.updateStudentPayPassword(student); + // 检查密码是否为空 + if (oldPassword == null || newPassword1 == null || newPassword2 == null) { + request.setAttribute("error", "密码不能为空"); + } + // 检查两次密码是否一致 + else if (!newPassword1.equals(newPassword2)) { + request.setAttribute("error", "两次密码输入不同"); + } + // 检查密码是否为数字 + else if (!newPassword1.matches("\\d+")) { + request.setAttribute("error", "必须输入数字"); + } + // 检查密码是否为6位 + else if (newPassword1.length() != 6) { + request.setAttribute("error", "密码必须为6位数字"); + } + // 验证旧支付密码是否正确 + else { + // 从数据库中获取当前的支付密码 + String currentPayPassword = studentDAO.getPayPasswordBySname(uname); + + if (!oldPassword.equals(currentPayPassword)) { + request.setAttribute("error", "旧支付密码不正确"); + } else { + // 如果验证通过,更新支付密码 + boolean updated = studentDAO.updatePayPasswordBySname(uname, newPassword1); if (updated) { - response.sendRedirect(request.getContextPath() + "/student.jsp"); - return; // 添加return以避免后续代码执行 + response.sendRedirect(request.getContextPath() + "/defaultPage.jsp"); + return; // 更新成功后,避免后续代码执行 } else { request.setAttribute("error", "设置失败"); } } - request.getRequestDispatcher("/studentChangePayPassword.jsp").forward(request, response); - } else { - response.sendRedirect(request.getContextPath() + "/error.jsp"); } + request.getRequestDispatcher("/studentChangePayPassword.jsp").forward(request, response); } else { response.sendRedirect(request.getContextPath() + "/login.jsp"); } diff --git a/src/main/java/com/tjl/servlet/StudentInfoServlet.java b/src/main/java/com/tjl/servlet/StudentInfoServlet.java index e17b5d12cfe19ad8a675afe7491d38a4679c2a1c..af119c8eedf0b354d37b0fc85b3dd1cc61bd8191 100644 --- a/src/main/java/com/tjl/servlet/StudentInfoServlet.java +++ b/src/main/java/com/tjl/servlet/StudentInfoServlet.java @@ -25,13 +25,13 @@ public class StudentInfoServlet extends HttpServlet { Info info = studentDAO.getInfoById(student.getInfoId()); request.setAttribute("student", student); request.setAttribute("info", info); - request.getRequestDispatcher("studentInfo.jsp").forward(request, response); // ȷ±£·¾¶Õýȷ + request.getRequestDispatcher("studentInfo.jsp").forward(request, response); } else { - request.setAttribute("error", "ûÓÐÕҵ½¶ÔӦµÄѧÉúÐÅϢ¡£"); + request.setAttribute("error", "错误"); request.getRequestDispatcher("/WEB-INF/jsp/error.jsp").forward(request, response); } } else { - response.sendRedirect(request.getContextPath() + "/login.jsp"); // ʹÓÃÖض¨Ï򵽵ǼҳÃæ + response.sendRedirect(request.getContextPath() + "/login.jsp"); } } } \ No newline at end of file diff --git a/src/main/webapp/ChangePassword.jsp b/src/main/webapp/ChangePassword.jsp index 44389d7b70570c79354bc5d66ebd7bba45b5b11a..27f3b30057a9a17f0f9215c6579cb320217ef1c4 100644 --- a/src/main/webapp/ChangePassword.jsp +++ b/src/main/webapp/ChangePassword.jsp @@ -1,106 +1,109 @@ <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <%@ page contentType="text/html;charset=UTF-8" language="java" %> - + + + 修改密码 +
-

修改密码

+

修改密码




- + -

${error}

+
${error}
+ diff --git a/src/main/webapp/TeacherChangeInfo.jsp b/src/main/webapp/TeacherChangeInfo.jsp index 77068ab9b5ab32cf1218cb5801f806ef5d7bd036..edefe15bf07a352ba93b9ad3e0bc4b57edcd93b2 100644 --- a/src/main/webapp/TeacherChangeInfo.jsp +++ b/src/main/webapp/TeacherChangeInfo.jsp @@ -10,51 +10,39 @@ font-family: Arial, sans-serif; margin: 0; padding: 0; - background-color: #e9f1f9; /* Light blue background */ - } - - /* Left-top link styling */ - a.return-link { - position: fixed; - top: 20px; - left: 20px; - font-size: 16px; - color: #333; /* Black text */ - text-decoration: none; - font-weight: bold; - padding: 10px 20px; - background-color: #ffffff; /* White background */ - border-radius: 4px; - box-shadow: 0 0 5px rgba(0, 0, 0, 0.1); /* Add subtle shadow */ - } - - a.return-link:hover { - text-decoration: underline; - background-color: #007bff; /* Blue background on hover */ - color: white; /* White text on hover */ + background-color: #f4f8fb; /* 浅蓝色背景 */ + display: flex; + justify-content: flex-end; /* 使页面内容靠右对齐 */ + height: 100vh; /* 页面高度充满屏幕 */ } + /* 主内容区域 */ #content { - width: 80%; + width: 80%; /* 内容区域占屏幕的80% */ margin: 20px auto; - background-color: #fff; + background-color: #ffffff; padding: 20px; - box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); + box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); /* 为内容区域添加阴影 */ border-radius: 8px; - margin-top: 60px; /* Offset from the fixed link */ + margin-top: -20px; /* 设置与固定返回链接的间距 */ } - h2 { + /* 页面标题样式 */ + h1 { + color: #007bff; text-align: center; - color: #004b87; /* Dark blue */ + padding: 20px 20px 0px 20px; + margin: 0; + background-color: #ffffff; + box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1); } h3 { - color: #004b87; + color: #007bff; } a { - color: #004b87; + color: #007bff; text-decoration: none; font-size: 18px; } @@ -64,28 +52,30 @@ } table { + text-align: center; width: 100%; border-collapse: collapse; margin-top: 20px; } - th, td { - border: 1px solid #ddd; - padding: 10px; - text-align: left; - } + th, td { + border: 1px solid #ddd; + padding: 10px; + text-align: center; /* 将文字居中 */ +} + th { - background-color: #0066cc; /* Blue */ + background-color: #007bff; /* 蓝色背景 */ color: white; } tr:nth-child(even) { - background-color: #f4faff; /* Light blue for even rows */ + background-color: #f4faff; /* 偶数行使用浅蓝色背景 */ } tr:hover { - background-color: #e1f0ff; /* Hover effect */ + background-color: #e1f0ff; /* 鼠标悬浮时的高亮效果 */ } #addInfo { @@ -96,7 +86,7 @@ margin-right: auto; padding: 20px; background-color: white; - box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1); /* Box shadow */ + box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1); /* 增加阴影效果 */ border-radius: 8px; } @@ -106,11 +96,11 @@ border: 1px solid #ccc; border-radius: 4px; margin-bottom: 10px; - box-sizing: border-box; /* Make the width full */ + box-sizing: border-box; /* 确保宽度占满整个输入框 */ } input[type="submit"], button { - background-color: #0066cc; + background-color: #007bff; color: white; padding: 8px 16px; border: none; @@ -120,19 +110,19 @@ } input[type="submit"]:hover, button:hover { - background-color: #005bb5; /* Darker blue on hover */ + background-color: #005bb5; /* 鼠标悬浮时深蓝色 */ } .form-container { margin-bottom: 20px; } - /* "增加" button styling */ + /* "增加"按钮样式 */ .add-btn { display: block; width: 200px; margin: 20px auto; - background-color: #0066cc; + background-color: #007bff; color: white; padding: 12px; border-radius: 5px; @@ -159,18 +149,16 @@ - - 返回老师主页
-

Info List

+

老师查看学生

- +
- +

增加信息

@@ -182,7 +170,7 @@
- + diff --git a/src/main/webapp/TeacherSetFee.jsp b/src/main/webapp/TeacherSetFee.jsp index bbf6ce203729405f2b479e2f5e0dfd8633d086eb..a13cba07a56ce8eeda88881e642cc54dcdd237e5 100644 --- a/src/main/webapp/TeacherSetFee.jsp +++ b/src/main/webapp/TeacherSetFee.jsp @@ -4,37 +4,36 @@ 设置学费 - - 返回老师主页 -

设置学费

+ +
+

设置学费

@@ -138,6 +138,7 @@
ID


+
+ + + + \ No newline at end of file diff --git a/src/main/webapp/defaultPage.jsp b/src/main/webapp/defaultPage.jsp new file mode 100644 index 0000000000000000000000000000000000000000..68ab053da44b3c0c737991f2e505b026f7b4e6e5 --- /dev/null +++ b/src/main/webapp/defaultPage.jsp @@ -0,0 +1,14 @@ +<%@ page language="java" contentType="text/html; charset=UTF-8" + pageEncoding="UTF-8"%> + + + + +Insert title here + + +

欢迎来到高校学生报名缴费管理系统!

+

请选择左侧的功能链接。

+ + + \ No newline at end of file diff --git a/src/main/webapp/student.jsp b/src/main/webapp/student.jsp index c2bb48e8382f2788c875c6de64a9d5b0d50cf99f..65b5242bfe0c6e0dac94d4fdb7dc4b695ace33ea 100644 --- a/src/main/webapp/student.jsp +++ b/src/main/webapp/student.jsp @@ -7,17 +7,16 @@ /* 全局样式 */ body { font-family: Arial, sans-serif; - background-color: #f4f9fc; /* 淡蓝色背景 */ + background-color: #f4f9fc; margin: 0; padding: 0; display: flex; - flex-direction: column; - align-items: center; + height: 100vh; box-sizing: border-box; } - /* 导航栏样式 */ - .navbar { + /* 导航栏样式 (上方) */ + .student-top-nav { width: 100%; padding: 10px; background-color: #0066cc; /* 蓝色背景 */ @@ -31,12 +30,12 @@ z-index: 1000; } - .navbar h2 { + .student-top-nav h2 { margin: 0; font-size: 1.5em; } - .navbar a { + .student-top-nav a { color: white; text-decoration: none; padding: 8px 16px; @@ -45,90 +44,94 @@ transition: background-color 0.3s; } - .navbar a:hover { + .student-top-nav a:hover { background-color: #004d99; /* 蓝色悬停效果 */ } - /* 页面主体部分 */ - .main-content { - margin-top: 60px; /* 给导航栏留出空间 */ - padding: 20px; - display: flex; - flex-wrap: wrap; - justify-content: space-around; /* 使框自动填充 */ - width: 100%; - box-sizing: border-box; - gap: 20px; /* 添加间距 */ - } - - /* 每个功能链接的box */ - .feature-box { + /* 左侧导航栏样式 */ + .student-left-nav { + width: 220px; background-color: #0066cc; /* 蓝色背景 */ color: white; - margin: 10px; - padding: 20px; - border-radius: 8px; - width: 260px; /* 设置宽度 */ - height: 260px; /* 将高度调整为原来的一半 */ + padding: 20px 10px; + box-sizing: border-box; display: flex; - justify-content: center; - align-items: center; - text-align: center; - box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1); /* 阴影效果 */ - transition: transform 0.3s ease, box-shadow 0.3s ease; + flex-direction: column; + position: fixed; + top: 60px; /* 给上方导航栏留出空间 */ + left: 0; + height: calc(100vh - 60px); /* 留出上方导航栏的空间 */ + overflow-y: auto; } - .feature-box:hover { - transform: translateY(-5px); /* 鼠标悬停时的效果 */ - box-shadow: 0 8px 20px rgba(0, 0, 0, 0.2); /* 更强的阴影 */ + .student-left-nav h2 { + margin: 0 0 20px; + font-size: 1.5em; + text-align: center; } - .feature-box a { + .student-left-nav a { color: white; text-decoration: none; - font-size: 1.1em; - transition: color 0.3s; + padding: 10px 15px; + margin-bottom: 10px; + font-size: 1em; + border-radius: 5px; + transition: background-color 0.3s; } - .feature-box a:hover { - color: #e0e0e0; /* 链接悬停颜色 */ + .student-left-nav a:hover { + background-color: #004d99; /* 蓝色悬停效果 */ + } + + /* 右侧内容区域样式 */ + .student-main-content { + margin-left: 240px; /* 给左侧导航留出空间 */ + padding: 20px; + width: calc(100% - 240px); + box-sizing: border-box; + overflow-y: auto; + height: calc(100vh - 60px); /* 留出上方导航栏的空间 */ + background-color: #f4f9fc; + margin-top: 60px; /* 防止内容被上方导航栏遮挡 */ + } + + iframe { + width: 100%; + height: 100%; + border: none; } - -