add<用户删除>
parent
396261c562
commit
58d20e5b1b
|
|
@ -0,0 +1,27 @@
|
||||||
|
package example.controller;
|
||||||
|
|
||||||
|
import example.dao.UserDao;
|
||||||
|
|
||||||
|
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 java.io.IOException;
|
||||||
|
|
||||||
|
@WebServlet("/deleteUserServlet")
|
||||||
|
public class DeleteUserServlet extends HttpServlet {
|
||||||
|
|
||||||
|
UserDao userDao=new UserDao();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||||
|
String id = req.getParameter("id");
|
||||||
|
try {
|
||||||
|
userDao.deleteUser(Integer.parseInt(id));
|
||||||
|
req.getRequestDispatcher("/user?action=list").forward(req,resp);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -28,13 +28,9 @@ public class RegisterServlet extends HttpServlet {
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
response.setContentType("text/html; charset=UTF-8");
|
|
||||||
response.setCharacterEncoding("UTF-8");
|
|
||||||
response.getWriter().println("<html><body>");
|
|
||||||
response.getWriter().println("</body></html>");
|
|
||||||
if (save > 0) {
|
if (save > 0) {
|
||||||
response.getWriter().println("注册成功~");
|
request.setAttribute("msg","注册成功");
|
||||||
|
request.getRequestDispatcher("msg.jsp").forward(request, response);
|
||||||
} else {
|
} else {
|
||||||
response.getWriter().println("注册失败~");
|
response.getWriter().println("注册失败~");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,52 @@
|
||||||
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
|
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<script src="https://www.liyansheng.top/cdn/watermark.js"></script>
|
<script src="https://www.liyansheng.top/cdn/watermark.js"></script>
|
||||||
</head>
|
<style>
|
||||||
|
body {
|
||||||
|
font-family: Arial, sans-serif;
|
||||||
|
background-color: #f0f8ff; /* 天蓝色背景 */
|
||||||
|
color: #333; /* 深色文本 */
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
height: 100vh;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
<body>
|
h2 {
|
||||||
<h2>提示:</h2>
|
color: #4682b4; /* 天蓝色标题 */
|
||||||
<h3>${sessionScope.msg}</h3>
|
margin-bottom: 20px;
|
||||||
<button onclick="window.history.back();">返回</button>
|
}
|
||||||
|
|
||||||
</body>
|
h3 {
|
||||||
|
color: #d9534f; /* 红色提示信息 */
|
||||||
|
margin-bottom: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
</html>
|
button {
|
||||||
|
background-color: #4682b4; /* 天蓝色按钮 */
|
||||||
|
color: white;
|
||||||
|
padding: 10px;
|
||||||
|
border: none;
|
||||||
|
border-radius: 4px;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
button:hover {
|
||||||
|
background-color: #5a9bd3; /* 按钮悬停时颜色 */
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<h2>提示:</h2>
|
||||||
|
<h3>${requestScope.msg}</h3>
|
||||||
|
<button onclick="window.history.back();">返回</button>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
|
|
|
||||||
|
|
@ -137,7 +137,7 @@
|
||||||
<td>${user.phone}</td>
|
<td>${user.phone}</td>
|
||||||
<td>${user.role}</td>
|
<td>${user.role}</td>
|
||||||
<td>
|
<td>
|
||||||
<a href="javascript:void(0)" >Delete</a>
|
<a href="/deleteUserServlet?id=${user.id}" >删除</a>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</c:forEach>
|
</c:forEach>
|
||||||
|
|
|
||||||
Reference in New Issue