我有一个带参数的Person.class:名称,年龄,电子邮件,并且我有一个jsp表单用于将新用户添加到ArrayList中。
@WebServlet(urlPatterns = "/addclientform.jsp")
public class AddClientServlet extends HttpServlet {
private PersonStorage personlist1 = new PersonStorage();
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String name = req.getParameter("name");
int age = Integer.parseInt(req.getParameter("age"));
String email = req.getParameter("email");
Person person = new Person(name, age, email);
personlist1.addPerson(person);
req.setAttribute("list", personlist1);
req.getRequestDispatcher("clientList.jsp").forward(req,resp);
}
}
<html>
<head>
<title>Clien Page</title>
</head>
<body>
<table>
<tr>
<th>Name</th>
<th>Age</th>
<th>Email</th>
</tr>
<c:forEach items="${list}" var="personlist">
<tr>
<td>${personlist.name}</td>
<td>${personlist.age}</td>
<td>${personlist.email}</td>
</tr>
</c:forEach>
</table>
<form name="home" action="home.jsp" method="post">
<input type="submit" value="back">
</form>
</body>
</html>
但是当我想查看所有用户时,我无法执行此操作。 我在哪里弄错了?
答案 0 :(得分:0)
您需要在页面顶部添加以下指令:
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>