package com.sponge.servlet;
import java.io.IOException;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.sponge.dao.UserDao;
import com.sponge.entity.User;
@WebServlet("/showServlet")
public class ShowServlet extends HttpServlet { // 显示全部数据
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
this.doPost(req, resp);
}
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
AdminDao dao = new AdminDao();
List userList = dao.getAll();
// servlet中存放list集合
req.setAttribute("userList", userList);
req.getRequestDispatcher("index.jsp").forward(req, resp);
}
}<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>显示</title>
<style type="text/css">
table {
border: 1px solid pink;
margin: 0 auto;
}
td{
width: 150px;
border: 1px solid pink;
text-align: center;
}
</style>
</head>
<body>
<table>
<tr>
<td>编号</td>
<td>帐号</td>
<td>密码</td>
<td>操作</td>
</tr>
<c:forEach items="${userList}" var="user">
<tr>
<td>${user.id }</td>
<td>${user.username }</td>
<td>${user.userpwd }</td>
</tr>
</c:forEach>
</table>
</body>
</html>
编程那点事
