From cb15a3e63648230d3d640cf510afc6d1d6587afe Mon Sep 17 00:00:00 2001
From: pck9l3ejt <3282667357@qq.com>
Date: Mon, 28 Apr 2025 20:01:39 +0800
Subject: [PATCH] Delete 'RManager.md'
---
RManager.md | 3051 ---------------------------------------------------
1 file changed, 3051 deletions(-)
delete mode 100644 RManager.md
diff --git a/RManager.md b/RManager.md
deleted file mode 100644
index a04a041..0000000
--- a/RManager.md
+++ /dev/null
@@ -1,3051 +0,0 @@
-/*
-filter 包:Java Web 中 Filter 用于过滤请求,处理编码、权限验证、XSS 防护等。比如图中的 AdminFilter、XSSFilter,分别做权限和防攻击。
-javabean 包:存放实体类,封装数据,对应数据库表或业务数据。像 Admin、Manager 这些类,用于存储属性,遵循 JavaBean 规范,有 getter/setter 等。
-servlet 包:处理客户端请求,接收参数,调用业务逻辑,返回响应。比如 ManagerLogin 处理登录请求,Announcement 相关的处理公告操作。
-现在组织这些内容,分三个部分解释每个包的作用,确保清晰准确。
-*/
-
-// * * * CharacterEncondingFilter.java
-/**
-* 字符编码过滤器,用于统一设置请求与响应的字符编码为UTF-8,解决文本乱码问题
- */
- public class CharacterEncodingFilter implements Filter {
-
- /**
- * 过滤器初始化方法,由容器调用,用于获取过滤器配置参数等初始化操作
- * @param filterConfig 过滤器配置对象,可从中读取初始化参数
- * @throws ServletException 初始化过程中发生异常时抛出
- */
- public void init(FilterConfig filterConfig) throws ServletException {
- }
-
- /**
- * 执行过滤逻辑的核心方法,处理请求响应的编码设置
- * @param servletRequest 客户端发送的请求对象
- * @param servletResponse 服务器返回的响应对象
- * @param filterChain 过滤链,用于将请求响应传递给后续处理组件
- * @throws IOException 输入输出操作异常
- * @throws ServletException Servlet处理过程异常
- */
- public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
- // 设置请求编码为UTF-8,确保接收参数时字符编码统一
- servletRequest.setCharacterEncoding("UTF-8");
- // 设置响应编码为UTF-8,确保返回数据的字符编码统一
- servletResponse.setCharacterEncoding("UTF-8");
- // 将请求和响应传递给过滤链中的下一个组件(如其他过滤器或Servlet)
- filterChain.doFilter(servletRequest, servletResponse);
- }
-
- /**
- * 过滤器销毁方法,由容器调用,用于释放过滤器占用的资源
- * 当前过滤器无需要释放的资源,方法体为空
- */
- public void destroy() {
- }
- }
-// * * * ManagerFilter.java
-package filter;
-import java.io.IOException;
-import javax.servlet.Filter;
-import javax.servlet.FilterChain;
-import javax.servlet.FilterConfig;
-import javax.servlet.ServletException;
-import javax.servlet.ServletRequest;
-import javax.servlet.ServletResponse;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import javax.servlet.http.HttpSession;
-// * 图书管理员过滤类,用于拦截请求并校验用户是否为登录状态的图书管理员* 实现Filter接口,完成请求过滤逻辑
- public class ManagerFilter implements Filter {
-// * 过滤器销毁方法,用于释放资源* 在过滤器生命周期结束时调用,此处暂无资源释放操作
- public void destroy() {
- }
- /**
- * 核心过滤方法,处理请求过滤逻辑
- * @param request 客户端发送的请求对象
- * @param response 服务器返回的响应对象
- * @param chain 过滤器链,用于传递请求和响应
- * @throws IOException IO异常
- * @throws ServletException Servlet处理异常
- */
- public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
- throws IOException, ServletException {
- // 将通用请求对象转换为Http请求对象
- HttpServletRequest req = (HttpServletRequest) request;
- // 获取请求对应的HttpSession
- HttpSession session = req.getSession();
- // 检查session是否存在,以及session中是否存在标识管理员登录的"manager"属性
- if (session == null || session.getAttribute("manager") == null) {
- // 将通用响应对象转换为Http响应对象
- HttpServletResponse rep = (HttpServletResponse) response;
- // 重定向到管理员登录页面,阻止未登录用户访问受保护资源
- rep.sendRedirect(req.getContextPath() + "/loginManager.html");
- return; // 终止后续过滤逻辑
- }
- // 将请求和响应传递给过滤器链中的下一个组件(如其他过滤器或Servlet)
- chain.doFilter(request, response);
- }
-
-// * 过滤器初始化方法,用于获取配置参数等初始化操作* @param fConfig 过滤器配置对象* @throws ServletException Servlet初始化异常
-public void init(FilterConfig fConfig) throws ServletException {
-}
-}
-// * XSS过滤器,用于过滤请求参数中的跨站脚本攻击代码(如 script、style 标签等),保护应用免受 XSS 攻击
- public class XSSFilter implements Filter {
-
- /**
- * 过滤输入字符串中的 XSS 相关代码
- * @param htmlStr 待过滤的字符串
- * @return 过滤后的字符串,移除了 script、style、HTML 标签内容
- */
- public String filter(String htmlStr) {
- if (htmlStr == null) {
- return null;
- }
- // 定义匹配 script 标签的正则表达式,不区分大小写
- String regEx_script = "
-
-
-
-
借阅图书
-
-
-
-
-
-
-
- <%
- // 获取表单提交参数
- String user = request.getParameter("userid"); // 借阅证号
- String book = request.getParameter("bookid"); // 图书编号
- String date1 = request.getParameter("date1"); // 借阅日期
-
- // 查询借阅证信息
- String sql1 = "select * from borrow_card where ID =" + user;
- ResultSet rs1 = borrow.executeQuery(sql1);
-
- // 管理员登录验证
- if (session.getAttribute("manager") != null) {
- if (rs1.next()) {
- // 获取借阅证状态和规则ID
- String rule = rs1.getString("rule_id");
- int cardstatus = Integer.parseInt(rs1.getString("STATUS"));
-
- // 查询借阅规则
- String sql4 = "select * from rules where id = " + rule;
- ResultSet rs4 = borrow.executeQuery(sql4);
- int n = 0; // 借阅天数
- String library = ""; // 可借阅图书馆
- String[] libraryArray = {};
- int num = 0; // 最大借阅数量
-
- while (rs4.next()) {
- n = rs4.getInt("limit_day");
- library = rs4.getString("borrow_library");
- libraryArray = library.split("、");
- num = rs4.getInt("borrow_num");
- }
-
- // 计算应还日期
- EndTime endtime = new EndTime();
- String end = endtime.show(n);
-
- // 借阅证状态检查
- if (cardstatus != 0) {
- // 查询图书信息
- String sql2 = "select * from books where ID =" + book;
- ResultSet rs2 = borrow.executeQuery(sql2);
-
- if (rs2.next()) {
- int status = Integer.parseInt(rs2.getString("STATUS")); // 图书状态
- String lib = Integer.toString(rs2.getInt("library_id")); // 图书所在图书馆
-
- // 检查图书是否在可借阅图书馆列表
- boolean validLibrary = false;
- for (int z = 0; z < libraryArray.length; z++) {
- if (libraryArray[z].equals(lib)) {
- validLibrary = true;
-
- // 查询当前用户未处理的借阅数量
- String countSql = "select count(*) as count from borrow_books where manager_id is null and card_id =" + user;
- ResultSet rsSql = borrow.executeQuery(countSql);
- int count = 0;
- while (rsSql.next()) {
- count = rsSql.getInt("count");
- }
-
- // 检查借阅数量限制
- if (count < num) {
- if (status == 1) { // 图书可用
- // 执行借阅操作
- String sql = "insert borrow_books(CARD_ID,BOOK_ID,BORROW_DATE,END_DATE) values('" + user + "','" + book + "','" + date1 + "','" + end + "')";
- try {
- int i = borrow.executeUpdate(sql);
- if (i == 1) {
- // 更新图书状态为已借出
- borrow.executeUpdate("update books set STATUS=0 where ID=" + book);
- %>
-
- <%
- } else {
- %>
-
- <%
- }
- } catch (Exception e) {
- %>
-
- <%
- }
- } else {
- %>
-
- <%
- }
- } else {
- %>
-
- <%
- }
- break;
- }
- }
-
- // 图书馆权限检查失败
- if (!validLibrary) {
- %>
-
- <%
- }
- } else {
- %>
-
- <%
- }
- } else {
- %>
-
- <%
- }
- } else {
- %>
-
- <%
- }
- } else {
- %>
-
- <%
- }
- %>
-
-
-
-
查询图书是否逾期
-
-
-
-
-
-
-
- <%
- // 获取表单提交的图书编号
- String book = request.getParameter("bookid");
- session.setAttribute("book", book); // 将会话保存到session
-
- // 管理员登录验证
- if (session.getAttribute("manager") != null) {
- DateTime date = new DateTime();
- String now = date.show(); // 获取当前时间
- String bookid = request.getParameter("bookid");
-
- // 查询该图书的借阅记录
- String sql = "select * from borrow_books where book_id = " + bookid;
- ResultSet rs = judge.executeQuery(sql);
- String end = ""; // 应还日期
- String ret = ""; // 归还日期
- String card = ""; // 借阅证号
-
- while (rs.next()) {
- end = rs.getString("end_date");
- ret = rs.getString("return_date");
- card = rs.getString("card_id");
- }
-
- if (ret == null) { // 图书未归还
- // 计算逾期天数(now与end的时间差)
- long n = CompareDate.show(now, end);
- session.setAttribute("days", n); // 保存逾期天数
-
- // 查询借阅证规则
- String sql1 = "select * from borrow_card where id = " + card;
- ResultSet rs1 = judge.executeQuery(sql1);
- String rule = "";
- while (rs1.next()) {
- rule = rs1.getString("rule_id");
- }
-
- // 查询逾期费用规则
- String sql2 = "select * from rules where id = " + rule;
- ResultSet rs2 = judge.executeQuery(sql2);
- String fee = "";
- while (rs2.next()) {
- fee = rs2.getString("overtime_fee");
- }
- session.setAttribute("fee", fee); // 保存逾期费用
-
- // 跳转到图书归还页面
- %>
-
- <%
- } else { // 图书已归还
- %>
-
- <%
- }
- } else { // 未登录处理
- %>
-
- <%
- }
- %>
-
-
-
-
-
-
-
归还图书
-
-
-
-
- <%
- // 从会话中获取逾期天数、罚款金额和图书编号
- Object days = session.getAttribute("days");
- Object fee = session.getAttribute("fee");
- String book = session.getAttribute("book").toString();
-
- // 初始化提示信息
- String mes = "";
- String mes2 = "";
- float sum = 0;
-
- // 根据逾期天数计算罚款
- if (days != null && fee != null) {
- int d = Integer.parseInt(days.toString());
- float f = Float.parseFloat(fee.toString());
- if (d < 0) {
- mes = "已逾期 " + (-d) + " 天";
- sum = d * f * (-1); // 计算罚款总额
- mes2 = "罚款金额:¥" + sum;
- } else {
- mes = "还剩 " + d + " 天";
- }
- // 将提示信息保存到会话中
- session.setAttribute("mes", mes);
- session.setAttribute("mes2", mes2);
- }
- %>
-
-
-
-
-
-
-
-
-
-
-
- <%
- // 获取表单提交参数
- String book = request.getParameter("bookid"); // 图书编号
- String date1 = request.getParameter("date1"); // 归还日期
- String ill = request.getParameter("ill"); // 违规信息(可选)
- String managerid = request.getParameter("managerid"); // 管理员编号
-
- // 管理员登录验证
- if (session.getAttribute("manager") != null) {
- try {
- // 查询图书当前状态
- String sql2 = "select * from books where ID = " + book;
- ResultSet rs2 = ret.executeQuery(sql2);
-
- if (rs2.next()) {
- int status = Integer.parseInt(rs2.getString("STATUS"));
-
- // 图书状态检查(0表示已借出,1表示可借阅)
- if (status == 0) {
- // 更新借阅记录:设置归还日期、违规信息和处理管理员
- String sql = "update borrow_books " +
- "set RETURN_DATE = ?, ILLEGAL = ?, MANAGER_ID = ? " +
- "where manager_id is null and BOOK_ID = ?";
-
- // 执行更新操作
- int i = ret.executeUpdate(sql, new Object[]{date1, ill, managerid, book});
-
- // 更新图书状态为可借阅
- ret.executeUpdate("update books set STATUS = 1 where ID = ?", new Object[]{book});
-
- %>
-
- <%
- } else {
- %>
-
- <%
- }
- }
- } catch (SQLException e) {
- e.printStackTrace();
- %>
-
- <%
- }
- } else {
- %>
-
- <%
- }
- %>
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- <%
- // 获取URL参数中的公告ID
- String id = request.getParameter("id");
-
- // 数据库操作
- Connection connection = null;
- PreparedStatement pstmt = null;
- ResultSet resultSet = null;
-
- try {
- connection = Base.getConnection();
- // 使用预编译语句查询公告信息
- String sql = "select * from announcement where id=?";
- pstmt = connection.prepareStatement(sql);
- pstmt.setString(1, id);
- resultSet = pstmt.executeQuery();
-
- // 移动到结果集第一条记录
- if (resultSet.next()) {
- // 页面后续会使用这些数据
- }
- } catch (SQLException e) {
- e.printStackTrace();
- } finally {
- // 释放资源(此处未正确关闭,建议在finally中处理)
- }
- %>
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
修改密码
-
-
-
-
-
-
-
-
-
修改邮箱
-
-
-
-
-
-
-
-
-
修改名字
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- <%
- // 获取表单提交的参数
- String psw1 = request.getParameter("psw1"); // 新密码
- String psw2 = request.getParameter("psw2"); // 确认密码
- String email1 = request.getParameter("email1"); // 新邮箱
- String email2 = request.getParameter("email2"); // 确认邮箱
- String name1 = request.getParameter("name1"); // 新姓名
- String name2 = request.getParameter("name2"); // 确认姓名
-
- // 获取当前登录管理员账号
- String id = session.getAttribute("manager").toString();
-
- // 密码修改逻辑
- if (psw1 != null && psw2 != null) {
- // 验证密码一致性和非空
- if (psw1.equals(psw2) && !psw1.trim().isEmpty() && !psw2.trim().isEmpty()) {
- // 存在SQL注入风险!建议使用预编译语句
- String sql = "update manager set PASSWORD = ? where ACCOUNT = ?";
- try (Connection conn = check.getConnection();
- PreparedStatement pstmt = conn.prepareStatement(sql)) {
- pstmt.setString(1, psw1);
- pstmt.setString(2, id);
- int affectedRows = pstmt.executeUpdate();
-
- if (affectedRows == 1) {
- %>
-
- <%
- } else {
- %>
-
- <%
- }
- } catch (SQLException e) {
- e.printStackTrace();
- %>
-
- <%
- }
- } else {
- %>
-
- <%
- }
- }
- // 邮箱修改逻辑
- else if (email1 != null && email2 != null) {
- // 验证邮箱一致性和非空
- if (email1.equals(email2) && !email1.trim().isEmpty() && !email2.trim().isEmpty()) {
- // 建议添加邮箱格式验证(正则表达式)
- String sql = "update manager set EMAIL = ? where ACCOUNT = ?";
- try (Connection conn = check.getConnection();
- PreparedStatement pstmt = conn.prepareStatement(sql)) {
- pstmt.setString(1, email1);
- pstmt.setString(2, id);
- int affectedRows = pstmt.executeUpdate();
-
- if (affectedRows == 1) {
- %>
-
- <%
- } else {
- %>
-
- <%
- }
- } catch (SQLException e) {
- e.printStackTrace();
- %>
-
- <%
- }
- } else {
- %>
-
- <%
- }
- }
- // 姓名修改逻辑
- else if (name1 != null && name2 != null) {
- // 验证姓名一致性和非空
- if (name1.equals(name2) && !name1.trim().isEmpty() && !name2.trim().isEmpty()) {
- String sql = "update manager set NAME = ? where ACCOUNT = ?";
- try (Connection conn = check.getConnection();
- PreparedStatement pstmt = conn.prepareStatement(sql)) {
- pstmt.setString(1, name1);
- pstmt.setString(2, id);
- int affectedRows = pstmt.executeUpdate();
-
- if (affectedRows == 1) {
- %>
-
- <%
- } else {
- %>
-
- <%
- }
- } catch (SQLException e) {
- e.printStackTrace();
- %>
-
- <%
- }
- } else {
- %>
-
- <%
- }
- } else {
- %>
-
- <%
- }
- %>
-
-
-
-
-
-
-
-
-
-
-
- <%
- // 使用response.sendRedirect方法将页面重定向到指定的URL
- // 这里将页面重定向到名为04readerFrame.jsp的页面,该页面位于reader目录下
- response.sendRedirect("./reader/04readerFrame.jsp");
- %>
-
-
-// * * 02borrow.jsp
-
-
-
借阅图书
-
-
-
-
-
-
-
-
-
-// * * * 03borrowSus.jsp
-
-
-
借阅图书处理
-
-
-// * * * 04judge.jsp
-
-
-
查询图书是否逾期
-
-
-
-
-
-
-
-
-
-// * * * 04judgeSus.jsp
-
-
-
图书逾期查询处理
-
-
-// * * * 04return.jsp
-
-
-
归还图书
-
-
-
-
-
-
-
-// * * * 05returnSus.jsp
-
-
-
图书归还处理
-
-
-//* * * 06borrwoTable.jsp
-
-
-
-
借阅记录
-
-
-
-
-
-
-//* * * 07returnTable.jsp
-
-
-
待归还图书列表
-
-
-
-
-
-
-
-
-//* * * 08add.jsp
-
-
-
发布公告
-
-
-
-
-
-
-//* * *08edit.jsp
-
-
-
-
-
公告编辑
-
-
-//* * *09managerSelf.jsp
-
-
-
-
管理员个人资料
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-//* * *updateManager.jsp
-
-
-
管理员资料修改处理
-
-
-// * * * loginManager.html
-
-
-
图书管理员登录页面
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-// * * * src/main/webapp/index.jsp
-
-
-
-
Insert title here
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-