今天完成多条件查询的功能:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ page import="dao.DBUtil" %> <%@ page import="bean.student" %> <%@page import = "java.sql.*" %> <%@page import = "java.util.*" %> <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>首页</title> <script src="js/jquery-1.11.3.min.js"></script> <style> table{ 50%; margin: 0 auto; border:0; background:#CCC; color:#000; line-height:40px; font-size: 1.2em; } body{ background: url("img.png") no-repeat; background-size: cover; } </style> </head> <body> <% String sql="select * from student"; Connection conn= DBUtil.getConnection(); PreparedStatement papre=conn.prepareStatement(sql); ResultSet rs=papre.executeQuery(); List<student> list=new ArrayList<>(); while(rs.next()){ student stu=new student(); stu.setNum(rs.getString("num")); stu.setName(rs.getString("name")); stu.setSex(rs.getString("sex")); stu.setDate(rs.getString("date")); stu.setAddress(rs.getString("address")); list.add(stu); } %> <h1 align="center"><span style="color:red">学生管理</span></h1> <div> <table border="1" align="center"> <tr> <td colspan="4" align="center"> <a href="insert.jsp">添加信息</a> </td> <td colspan="3" align="center"> <a href="query.jsp">查询信息</a> </td> </tr> <tr> <td>学号</td> <td>姓名</td> <td>性别</td> <td>出生年月</td> <td>地址</td> <td colspan="2">操作</td> </tr> <tr> <c:forEach items="<%=list %>" var="item" varStatus="status"> <tr> <td>${item.num}</td> <td>${item.name}</td> <td>${item.sex}</td> <td>${item.date}</td> <td>${item.address}</td> <td><a href="Servlet?method=delete&num=${item.num}">删除</a></td> <td><a href="update.jsp?num=${item.num}&name=${item.name}&date=${item.date}&sex=${item.sex}&address=${item.address}">修改</a></td> </tr> </c:forEach> </tr> </table> </div> </body> </html>