package servlet;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.MulticastSocket;
import java.sql.Array;
import java.util.ArrayList;
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 dao.tdDao;
import dao.impl.tdDaoimpl;
import entity.td;
/**
* Servlet implementation class listservlet
*/
@WebServlet("/listservlet")
public class listservlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public listservlet() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter out= response.getWriter();
request.setCharacterEncoding("utf-8");
tdDao dao=new tdDaoimpl();
td t=new td();
ArrayList<td> list=(ArrayList<td>) dao.select();
request.setAttribute("list", list);
request.getRequestDispatcher("list.jsp").forward(request, response);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
}
<%@ page language="java" contentType="text/html; charset=UTF-8" import="java.util.*,entity.*,dao.*,dao.impl.*"
pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="f"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<c:set var="ArrayList list" value="(ArrayList) request.getAttribute('list')" scope="request"></c:set>
<table border="1" contenteditable="0" contextmenu="0">
<tr>
<td>编号</td>
<td>品牌名称</td>
<td>企业名称</td>
<td>排序字段<td>
<td>状态</td>
</tr>
<c:forEach var="s" items="${list}">
<tr>
<td>${s.id}</td>
<td>${s.brandname}</td>
<td>${s.companyname}</td>
<td>${s.orderd}</td>
<td>${s.status}</td>
<td><a href="add.jsp">添加</a> <a href="deleteservlet?id=${s.id}">注销</a> <a href="Toupdateservlet?id=${s.id}">修改</a></td>
</tr>
</c:forEach>
</table>
</body>
</html>
```