|
|
|
@ -1,31 +1,31 @@
|
|
|
|
|
package cn.train.controller;
|
|
|
|
|
package cn.train.controller; // 定义包名为cn.train.controller,用于组织代码结构
|
|
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.io.IOException; // 导入IOException类,用于处理可能的输入输出异常
|
|
|
|
|
|
|
|
|
|
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 javax.servlet.ServletException; // 导入ServletException类,用于处理Servlet运行时异常
|
|
|
|
|
import javax.servlet.annotation.WebServlet; // 导入WebServlet注解,用于声明Servlet
|
|
|
|
|
import javax.servlet.http.HttpServlet; // 导入HttpServlet类,是所有HTTP Servlet的父类
|
|
|
|
|
import javax.servlet.http.HttpServletRequest; // 导入HttpServletRequest接口,表示一个HTTP请求
|
|
|
|
|
import javax.servlet.http.HttpServletResponse; // 导入HttpServletResponse接口,表示一个HTTP响应
|
|
|
|
|
|
|
|
|
|
import cn.train.model.UserTable;
|
|
|
|
|
import cn.train.service.UserTableService;
|
|
|
|
|
@WebServlet("/GetInfoServlet")
|
|
|
|
|
public class GetInfoServlet extends HttpServlet {
|
|
|
|
|
|
|
|
|
|
import cn.train.model.UserTable; // 导入UserTable类,可能是用于表示用户数据的实体类
|
|
|
|
|
import cn.train.service.UserTableService; // 导入UserTableService类,可能是用于提供用户数据服务的类
|
|
|
|
|
|
|
|
|
|
@WebServlet("/GetInfoServlet") // 使用WebServlet注解声明这个Servlet的URL路径为/GetInfoServlet
|
|
|
|
|
public class GetInfoServlet extends HttpServlet { // 定义GetInfoServlet类,继承自HttpServlet
|
|
|
|
|
// 定义doGet方法,用于处理HTTP GET请求
|
|
|
|
|
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
|
|
|
|
String uname=req.getParameter("uname");
|
|
|
|
|
UserTableService userService=new UserTableService();
|
|
|
|
|
UserTable usertable=userService.getUser(uname);
|
|
|
|
|
if (usertable!=null) {
|
|
|
|
|
req.setAttribute("usertable", usertable);
|
|
|
|
|
req.getRequestDispatcher("back/updateuser.jsp").forward(req, resp);
|
|
|
|
|
String uname=req.getParameter("uname"); // 从请求中获取名为uname的参数值
|
|
|
|
|
UserTableService userService=new UserTableService(); // 创建UserTableService实例,用于访问用户服务
|
|
|
|
|
UserTable usertable=userService.getUser(uname); // 调用userService的getUser方法,根据uname获取用户信息
|
|
|
|
|
if (usertable!=null) { // 如果usertable不为null,即找到了用户信息
|
|
|
|
|
req.setAttribute("usertable", usertable); // 将usertable对象设置为请求属性,以便在JSP页面中使用
|
|
|
|
|
req.getRequestDispatcher("back/updateuser.jsp").forward(req, resp); // 转发请求到updateuser.jsp页面
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 定义doPost方法,用于处理HTTP POST请求
|
|
|
|
|
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
|
|
|
|
doGet(req,resp);
|
|
|
|
|
doGet(req,resp); // 重用doGet方法来处理POST请求
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|