<% String code = request.getParameter("YYM"); if (code == null || code.isEmpty()) { %> <a href="Admin.jsp">请输入预约码,点击返回签到</a> <% } else { Connection conn = SQLConn.openDB(); final String SELECT_SQL = "SELECT ACode FROM User_ZC JOIN YuYue ON User_ZC.UserId = YuYue.UserId WHERE Login = 1 AND State = 1 AND Arrive IS NULL"; final String UPDATE_SQL = "UPDATE YuYue SET Arrive =1 WHERE ACode = ?"; PreparedStatement pstmtSelect = conn.prepareStatement(SELECT_SQL); ResultSet rs = pstmtSelect.executeQuery(); int count = 0; while (rs.next()) { String Acode = rs.getString("ACode"); if (Acode.equals(code)) { try { PreparedStatement pstmtUpdate = conn.prepareStatement(UPDATE_SQL); pstmtUpdate.setString(1, code); count = pstmtUpdate.executeUpdate(); pstmtUpdate.close(); } catch (SQLException e) { e.printStackTrace(); } break; } } if (count > 0){ %> <a href="Admin.jsp">签到成功</a> <% } else { %> <a href="Admin.jsp">签到失败</a> <% } rs.close(); pstmtSelect.close(); conn.close(); } %>为什么总是跳转到“签到失败”页面,请找出bug
时间: 2024-02-15 17:27:44 浏览: 68
JSP用过滤器解决request getParameter中文乱码问题.docx
在代码中没有检查数据库连接是否成功打开。如果连接失败,会导致在执行SELECT语句时抛出SQLException异常。因此,建议在打开连接之后添加一个if语句来检查连接是否成功打开。另外,还需要检查是否有与该预约码相匹配的记录。如果没有,则也会导致跳转到“签到失败”页面。因此,建议添加一个else语句,在其中输出“该预约码无效”。
阅读全文