@WebServlet("/student")
public class StudentServlet extends HttpServlet {
private StudentDao studentDao = new StudentDao();
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Student student = new Student();
// 填充student对象
studentDao.insert(student);
List<Student> students = studentDao.listAll();
request.setAttribute("students", students);
request.getRequestDispatcher("/showRecord.jsp").forward(request, response);
}
}
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<body>
<table>
<c:forEach var="student" items="${students}">
<tr>
<td>${student.id}</td>
<td>${student.name}</td>
<td>${student.gender}</td>
<td>${student.age}</td>
<td>${student.department}</td>
</tr>
</c:forEach>
</table>
</body>
</html>