|
|
|
@ -1,43 +1,47 @@
|
|
|
|
|
package cn.train.controller;
|
|
|
|
|
package cn.train.controller; // 定义控制器包
|
|
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.io.IOException; // 导入IOException
|
|
|
|
|
import javax.servlet.ServletException; // 导入ServletException
|
|
|
|
|
import javax.servlet.annotation.WebServlet; // 导入@WebServlet注解
|
|
|
|
|
import javax.servlet.http.HttpServlet; // 导入HttpServlet
|
|
|
|
|
import javax.servlet.http.HttpServletRequest; // 导入HttpServletRequest
|
|
|
|
|
import javax.servlet.http.HttpServletResponse; // 导入HttpServletResponse
|
|
|
|
|
|
|
|
|
|
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 cn.train.model.UserTable; // 导入UserTable模型
|
|
|
|
|
import cn.train.service.UserTableService; // 导入UserTableService服务
|
|
|
|
|
|
|
|
|
|
import cn.train.model.UserTable;
|
|
|
|
|
import cn.train.service.UserTableService;
|
|
|
|
|
@WebServlet("/UpdateUserServlet")
|
|
|
|
|
@WebServlet("/UpdateUserServlet") // 注册Servlet,定义访问路径为/UpdateUserServlet
|
|
|
|
|
public class UpdateUserServlet extends HttpServlet {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 处理GET请求的方法
|
|
|
|
|
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
|
|
|
|
|
|
|
|
|
String uname=req.getParameter("name");
|
|
|
|
|
int state=Integer.parseInt(req.getParameter("userstate"));
|
|
|
|
|
UserTableService userService=new UserTableService();
|
|
|
|
|
UserTable usertable=new UserTable();
|
|
|
|
|
// 从请求中获取用户名和用户状态参数
|
|
|
|
|
String uname = req.getParameter("name");
|
|
|
|
|
int state = Integer.parseInt(req.getParameter("userstate"));
|
|
|
|
|
// 创建UserTableService实例
|
|
|
|
|
UserTableService userService = new UserTableService();
|
|
|
|
|
// 创建UserTable对象
|
|
|
|
|
UserTable usertable = new UserTable();
|
|
|
|
|
// 设置UserTable对象的用户名和状态
|
|
|
|
|
usertable.setUname(uname);
|
|
|
|
|
usertable.setState(state);
|
|
|
|
|
|
|
|
|
|
// 调用服务层方法更新用户信息,返回更新结果
|
|
|
|
|
boolean flag = userService.updateUserTab(usertable);
|
|
|
|
|
|
|
|
|
|
boolean flag=userService.updateUserTab(usertable);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 如果更新成功,转发到UserTableServlet
|
|
|
|
|
if (flag) {
|
|
|
|
|
req.getRequestDispatcher("UserTableServlet").forward(req, resp);
|
|
|
|
|
}else{
|
|
|
|
|
} else { // 如果更新失败,重定向到updateuser.jsp页面
|
|
|
|
|
resp.sendRedirect("back/updateuser.jsp");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 处理POST请求的方法,与GET请求处理相同
|
|
|
|
|
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
|
|
|
|
doGet(req,resp);
|
|
|
|
|
doGet(req, resp); // 直接调用doGet方法
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|