AdminServlet.jap
@WebServlet("/AdminServlet") public class AdminServlet extends HttpServlet { @Override protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("UTF-8"); String msg = null; /*获取区分多请求的参数*/ String type = request.getParameter("type"); AdminServiceImpl adminService = new AdminServiceImpl(); AdminEntity adminEntity = (AdminEntity) request.getSession().getAttribute("adminEntity"); if (adminEntity == null) { response.sendRedirect("/LoginServlet"); return; } switch (type) { case "admin": { { String userName = request.getParameter("userName"); if (userName == null) { userName = ""; } Integer id = adminEntity.getId(); List<Customer> list = adminService.adminList(userName, id); if (list == null) { return; } request.getSession().setAttribute("adminList", list); request.getRequestDispatcher("/WEB-INF/admin/admin.jsp").forward(request, response); break; } } case "deleteAdmin": { Integer id = Integer.valueOf(request.getParameter("id")); boolean b = adminService.deleteAdminById(id); if (b) { msg = "删除成功"; } else { msg = "删除失败"; } request.getSession().setAttribute("msg", msg); response.sendRedirect("/AdminServlet?type=admin"); break; } case "toUpdateAdmin": { List<AdminEntity> adminList = (List<AdminEntity>) request.getSession().getAttribute("adminList"); Integer id = Integer.valueOf(request.getParameter("id")); AdminEntity admin = new AdminEntity(); for (AdminEntity index : adminList) { if (index.getId().equals(id)) { admin = index; } } request.getSession().setAttribute("admin", admin); request.getRequestDispatcher("/WEB-INF/admin/adminUpdate.jsp").forward(request, response); break; } case "updateAdmin": { Integer id = Integer.valueOf(request.getParameter("id")); String userName = request.getParameter("userName"); String pwd = request.getParameter("pwd"); Integer state = Integer.valueOf(request.getParameter("state")); AdminEntity admin = new AdminEntity(); admin.setId(id); admin.setUserName(userName); admin.setPwd(pwd); admin.setState(state); boolean b = adminService.updateAdmin(admin); if (b) { request.getSession().setAttribute("msg", "修改成功"); response.sendRedirect("/AdminServlet?type=admin"); } else { request.getSession().setAttribute("msg", "修改失败"); response.sendRedirect("/AdminServlet?type=admin"); } break; } } } }
标签:userName,Javaweb,admin,request,getParameter,Integer,servlet,id From: https://www.cnblogs.com/gbrr/p/16890764.html