写一个jsp页面用于用户的增删改查以及批量删除,包含编号,姓名,邮箱,密码
时间: 2024-06-11 09:07:34 浏览: 77
以下是一个简单的实现:
```
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.List" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>User Management</title>
</head>
<body>
<h1>User Management</h1>
<hr>
<%-- 显示用户列表 --%>
<h2>User List</h2>
<table border="1">
<tr>
<th>ID</th>
<th>Name</th>
<th>Email</th>
<th>Password</th>
<th>Action</th>
</tr>
<%-- 模拟数据 --%>
<% List<User> userList = new ArrayList<User>(); %>
<% userList.add(new User(1, "Alice", "alice@example.com", "123456")); %>
<% userList.add(new User(2, "Bob", "bob@example.com", "123456")); %>
<% userList.add(new User(3, "Charlie", "charlie@example.com", "123456")); %>
<% for (User user : userList) { %>
<tr>
<td><%= user.getId() %></td>
<td><%= user.getName() %></td>
<td><%= user.getEmail() %></td>
<td><%= user.getPassword() %></td>
<td>
<a href="edit.jsp?id=<%= user.getId() %>">Edit</a>
<a href="delete.jsp?id=<%= user.getId() %>">Delete</a>
</td>
</tr>
<% } %>
</table>
<%-- 添加用户 --%>
<h2>Add User</h2>
<form action="add.jsp" method="post">
<label>ID:</label>
<input type="text" name="id"><br>
<label>Name:</label>
<input type="text" name="name"><br>
<label>Email:</label>
<input type="email" name="email"><br>
<label>Password:</label>
<input type="password" name="password"><br>
<input type="submit" value="Add">
</form>
<%-- 批量删除用户 --%>
<h2>Delete Users</h2>
<form action="delete.jsp" method="post">
<label>IDs (separated by comma):</label>
<input type="text" name="ids"><br>
<input type="submit" value="Delete">
</form>
</body>
</html>
```
在这个页面中,我们展示了用户列表,并提供了添加用户和批量删除用户的表单。注意,这个页面中的数据是模拟的,实际应用中需要从数据库中查询。
用户类的定义如下:
```
public class User {
private int id;
private String name;
private String email;
private String password;
public User(int id, String name, String email, String password) {
this.id = id;
this.name = name;
this.email = email;
this.password = password;
}
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 getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
```
注意,这个示例中并没有实现用户的增删改查功能,而是只提供了基本的界面和表单。实际应用中,需要根据业务需要实现相应的功能。
阅读全文