创建用户实体类User,编辑属性编号、姓名、手机、邮箱,创建user.jsp,编写程序动态输出用户列表,输出效果为列表形式,最上层为编号、姓名、手机、邮箱、操作有修改和删除
时间: 2024-01-31 13:02:32 浏览: 84
下面是User实体类代码:
```java
public class User {
private int id;
private String name;
private String phone;
private String email;
public User(int id, String name, String phone, String email) {
this.id = id;
this.name = name;
this.phone = phone;
this.email = email;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
}
```
下面是user.jsp代码:
```jsp
<%@ 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>
<html>
<head>
<meta charset="UTF-8">
<title>用户列表</title>
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
text-align: center;
}
th, td {
padding: 10px;
}
</style>
</head>
<body>
<h2>用户列表</h2>
<table>
<tr>
<th>编号</th>
<th>姓名</th>
<th>手机</th>
<th>邮箱</th>
<th>操作</th>
</tr>
<c:forEach items="${users}" var="user">
<tr>
<td>${user.id}</td>
<td>${user.name}</td>
<td>${user.phone}</td>
<td>${user.email}</td>
<td>
<a href="edit.jsp?id=${user.id}">修改</a>
<a href="delete.jsp?id=${user.id}">删除</a>
</td>
</tr>
</c:forEach>
</table>
</body>
</html>
```
在这里,我们使用了JSTL标准标签库的forEach标签,它可以循环输出用户列表。同时,我们在操作列中添加了修改和删除的链接。
阅读全文