12.11 今天弄明白了怎么在前端写Java实现查询功能
//例:
<% // Check if the query button is clicked if (request.getParameter("query") != null) { try { Connection connection = DatabaseConnection.getConnection(); String query = "SELECT AttendanceTime, Notes, JobID, Name FROM attendance WHERE AttendanceType = 2 AND ApprovedType = 0"; PreparedStatement preparedStatement = connection.prepareStatement(query); ResultSet resultSet = preparedStatement.executeQuery(); out.println("<div class='query-result mt-3'><h3>查询结果:</h3></div>"); while (resultSet.next()) { // Display data out.print("<div class='mt-2'>Attendance Time: " + resultSet.getTimestamp("AttendanceTime") + "</div>"); out.print("<div>Job ID: " + resultSet.getInt("JobID") + "</div>"); out.print("<div>Name: " + resultSet.getString("Name") + "</div>"); out.print("<div>Notes: " + resultSet.getString("Notes") + "</div>"); out.print("<hr>"); } resultSet.close(); preparedStatement.close(); connection.close(); } catch (SQLException | ClassNotFoundException e) { e.printStackTrace(); } } %> 类似于这种方法,点击查询后将内容体现在界面上,其他操作由该jsp页面对应的servlet来处理