diff --git a/src/com/landaiqing/dao/AdminUserDao.java b/src/com/landaiqing/dao/AdminUserDao.java index 5e7cb1d..d67d756 100644 --- a/src/com/landaiqing/dao/AdminUserDao.java +++ b/src/com/landaiqing/dao/AdminUserDao.java @@ -3,23 +3,22 @@ package com.landaiqing.dao; import com.landaiqing.entity.AdminUserEntity; import com.landaiqing.utils.JdbcUtils; -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; +import java.sql.*; import java.util.ArrayList; public class AdminUserDao { - private AdminUserEntity adminUserEntity=new AdminUserEntity(); + private AdminUserEntity adminUserEntity = new AdminUserEntity(); + /** * 管理员登录 - * */ + */ public AdminUserEntity login(String userName, String userPwd) { ResultSet resultSet = null; PreparedStatement preparedStatement = null; Connection connection = null; try { connection = JdbcUtils.getConnection(); - String loginSql = "select * from admin where adminUserName=? and adminPassword=?;"; + String loginSql = "select * from admin where adminUserName=? and adminPassword=? and is_valid='1';"; preparedStatement = connection.prepareStatement(loginSql); preparedStatement.setString(1, userName); preparedStatement.setString(2, userPwd); @@ -40,9 +39,10 @@ public class AdminUserDao { JdbcUtils.closeConnection(resultSet, preparedStatement, connection); } } + /** * 查询所有管理员 - * */ + */ public ArrayList selectAllAdmin() { ResultSet resultSet = null; PreparedStatement preparedStatement = null; @@ -52,12 +52,13 @@ public class AdminUserDao { String loginSql = "select * from admin;"; preparedStatement = connection.prepareStatement(loginSql); resultSet = preparedStatement.executeQuery(); - ArrayList adminUserDaos=new ArrayList<>(); + ArrayList adminUserDaos = new ArrayList<>(); while (resultSet.next()) { Integer id = resultSet.getInt(1); String dbUserName = resultSet.getString(2); String dbUserPwd = resultSet.getString(3); - AdminUserEntity adminUserEntity = new AdminUserEntity(id,dbUserName, dbUserPwd); + Integer isValid = resultSet.getInt(4); + AdminUserEntity adminUserEntity = new AdminUserEntity(id, dbUserName, dbUserPwd, isValid); adminUserDaos.add(adminUserEntity); } return adminUserDaos; @@ -68,4 +69,164 @@ public class AdminUserDao { JdbcUtils.closeConnection(resultSet, preparedStatement, connection); } } + + /** + * 打开管理员状态 + */ + public int OpenAdmin(Integer id) { + Connection connection = null; + PreparedStatement preparedStatement = null; + try { + connection = JdbcUtils.getConnection(); + JdbcUtils.beginTransaction(connection); + preparedStatement = connection.prepareStatement("UPDATE `admin` SET `is_valid` = ? WHERE `adminId` = ?;"); + preparedStatement.setInt(1, 1); + preparedStatement.setInt(2, id); + Integer result = preparedStatement.executeUpdate(); + JdbcUtils.commitTransaction(connection); + return result; + + } catch (SQLException e) { + JdbcUtils.rollBackTransaction(connection); + throw new RuntimeException(e); + + } finally { + JdbcUtils.closeConnection(null, preparedStatement, connection); + } + } + + /** + * 关闭管理员状态 + */ + public int CloseAdmin(Integer id) { + Connection connection = null; + PreparedStatement preparedStatement = null; + try { + connection = JdbcUtils.getConnection(); + JdbcUtils.beginTransaction(connection); + preparedStatement = connection.prepareStatement("UPDATE `admin` SET `is_valid` = ? WHERE `adminId` = ?;"); + preparedStatement.setInt(1, 0); + preparedStatement.setInt(2, id); + Integer result = preparedStatement.executeUpdate(); + JdbcUtils.commitTransaction(connection); + return result; + + } catch (SQLException e) { + JdbcUtils.rollBackTransaction(connection); + throw new RuntimeException(e); + + } finally { + JdbcUtils.closeConnection(null, preparedStatement, connection); + } + } + + /** + * 通过ID查询管理员 + */ + public AdminUserEntity getAdminByID(Integer id) { + Connection connection = null; + PreparedStatement preparedStatement = null; + ResultSet resultSet = null; + try { + connection = JdbcUtils.getConnection(); + preparedStatement = connection.prepareStatement("select * from admin where adminId=?;"); + preparedStatement.setInt(1, id); + resultSet = preparedStatement.executeQuery(); + if (!resultSet.next()) { + return null; + } + Integer adminId = resultSet.getInt("adminId"); + String adminUserName = resultSet.getString("adminUserName"); + String adminPassword = resultSet.getString("adminPassword"); + Integer isValid = resultSet.getInt("is_valid"); + AdminUserEntity adminUserEntity1 = new AdminUserEntity(adminId, adminUserName, adminPassword, isValid); + return adminUserEntity1; + } catch (SQLException e) { + throw new RuntimeException(e); + } finally { + JdbcUtils.closeConnection(resultSet, preparedStatement, connection); + } + } + + /** + * 修改管理员信息 + */ + public int updateAdmin(AdminUserEntity userEntity) { + Connection connection = null; + PreparedStatement preparedStatement = null; + try { + connection = JdbcUtils.getConnection(); + JdbcUtils.beginTransaction(connection); + preparedStatement = connection.prepareStatement("UPDATE `admin` SET `adminUserName` = ?, `adminPassword` = ?,`is_valid`=? WHERE `adminId` = ?;"); + + preparedStatement.setString(1, userEntity.getAdminUserName()); + preparedStatement.setString(2, userEntity.getAdminPassword()); + preparedStatement.setInt(3, userEntity.getIsValid()); + preparedStatement.setInt(4, userEntity.getAdminId()); + Integer result = preparedStatement.executeUpdate(); + JdbcUtils.commitTransaction(connection); + return result; + + } catch (SQLException e) { + JdbcUtils.rollBackTransaction(connection); + throw new RuntimeException(e); + + } finally { + JdbcUtils.closeConnection(null, preparedStatement, connection); + } + + } + /** + * 添加管理员 + * */ + + public int insertAdmin(AdminUserEntity adminUserEntity){ + Connection connection = null; + PreparedStatement preparedStatement = null; + try { + connection = JdbcUtils.getConnection(); + JdbcUtils.beginTransaction(connection); + preparedStatement = connection.prepareStatement("INSERT INTO `admin` (`adminId`, `adminUserName`, `adminPassword`, `is_valid`) VALUES (null, ?, ?, ?);"); + preparedStatement.setString(1,adminUserEntity.getAdminUserName()); + preparedStatement.setString(2,adminUserEntity.getAdminPassword()); + preparedStatement.setInt(3,adminUserEntity.getIsValid()); + Integer result = preparedStatement.executeUpdate(); + JdbcUtils.commitTransaction(connection); + return result; + + } catch (SQLException e) { + JdbcUtils.rollBackTransaction(connection); + throw new RuntimeException(e); + + } finally { + JdbcUtils.closeConnection(null, preparedStatement, connection); + } + } + + + /** + * 删除管理源 + * */ + + public int deleteAdmin(Integer id){ + Connection connection = null; + PreparedStatement preparedStatement = null; + try { + connection = JdbcUtils.getConnection(); + JdbcUtils.beginTransaction(connection); + preparedStatement = connection.prepareStatement("DELETE from `admin` WHERE `adminId` = ?;"); + preparedStatement.setInt(1,id); + Integer result = preparedStatement.executeUpdate(); + JdbcUtils.commitTransaction(connection); + return result; + + } catch (SQLException e) { + JdbcUtils.rollBackTransaction(connection); + throw new RuntimeException(e); + + } finally { + JdbcUtils.closeConnection(null, preparedStatement, connection); + } + } + } diff --git a/src/com/landaiqing/entity/AdminUserEntity.java b/src/com/landaiqing/entity/AdminUserEntity.java index 0fac2d4..03d50b7 100644 --- a/src/com/landaiqing/entity/AdminUserEntity.java +++ b/src/com/landaiqing/entity/AdminUserEntity.java @@ -15,6 +15,16 @@ public class AdminUserEntity { private Integer adminId; private String adminUserName; private String adminPassword; + private Integer isValid; + + + public AdminUserEntity(String adminUserName, String adminPassword) { + this.adminUserName = adminUserName; + this.adminPassword = adminPassword; + } + public AdminUserEntity(){ + + } public Integer getAdminId() { return adminId; @@ -40,18 +50,18 @@ public class AdminUserEntity { this.adminPassword = adminPassword; } - public AdminUserEntity(Integer adminId, String adminUserName, String adminPassword) { + public Integer getIsValid() { + return isValid; + } + + public void setIsValid(Integer isValid) { + this.isValid = isValid; + } + + public AdminUserEntity(Integer adminId, String adminUserName, String adminPassword, Integer isValid) { this.adminId = adminId; this.adminUserName = adminUserName; this.adminPassword = adminPassword; - } - - public AdminUserEntity(String adminUserName, String adminPassword) { - this.adminUserName = adminUserName; - this.adminPassword = adminPassword; - } - - public AdminUserEntity(){ - + this.isValid = isValid; } } diff --git a/src/com/landaiqing/filter/UserSessionFilter.java b/src/com/landaiqing/filter/UserSessionFilter.java index 4506a6b..415c80e 100644 --- a/src/com/landaiqing/filter/UserSessionFilter.java +++ b/src/com/landaiqing/filter/UserSessionFilter.java @@ -1,48 +1,48 @@ -package com.landaiqing.filter; - - -import jakarta.servlet.*; -import jakarta.servlet.annotation.WebFilter; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; -import jakarta.servlet.http.HttpSession; - -import java.io.IOException; - -/** - * 过滤器 - */ -@WebFilter("/System/*")// 过滤器所有的请求 -public class UserSessionFilter implements Filter { - private String[] excludeUrls = new String[]{"/login", "/publish","/reply","/VerifycodeServlet"}; - - @Override - public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { - // 从session获取到用户的会话信息 判断用户是否登录过 - HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest; - HttpServletResponse httpServletResponse = (HttpServletResponse) servletResponse; - String contextPath = httpServletRequest.getContextPath(); - // 定义一个数组 哪些 请求是需要排除的 - for (int i = 0; i < excludeUrls.length; i++) { - String excludeUrl = contextPath + excludeUrls[i]; - String requestURI = httpServletRequest.getRequestURI(); - if (excludeUrl.equals(requestURI)) { - // 放行请求 - filterChain.doFilter(httpServletRequest, httpServletResponse); - return; - } - } - // 排除请求 - HttpSession session = httpServletRequest.getSession(); - Object user = session.getAttribute("user"); - if (user == null) { - // 当前用户没有登录或者登录会话失效 - // 重定向到登录页面 - httpServletResponse.sendRedirect(contextPath+"/"); - return; - } - // 用户已经登录了 正常放行请求 - filterChain.doFilter(httpServletRequest, httpServletResponse); - } -} - +//package com.landaiqing.filter; +// +// +//import jakarta.servlet.*; +//import jakarta.servlet.annotation.WebFilter; +//import jakarta.servlet.http.HttpServletRequest; +//import jakarta.servlet.http.HttpServletResponse; +//import jakarta.servlet.http.HttpSession; +// +//import java.io.IOException; +// +///** +// * 过滤器 +// */ +//@WebFilter("/System/*")// 过滤器所有的请求 +//public class UserSessionFilter implements Filter { +// private String[] excludeUrls = new String[]{"/login", "/publish","/reply","/VerifycodeServlet","/System/showAdmin"}; +// +// @Override +// public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { +// // 从session获取到用户的会话信息 判断用户是否登录过 +// HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest; +// HttpServletResponse httpServletResponse = (HttpServletResponse) servletResponse; +// String contextPath = httpServletRequest.getContextPath(); +// // 定义一个数组 哪些 请求是需要排除的 +// for (int i = 0; i < excludeUrls.length; i++) { +// String excludeUrl = contextPath + excludeUrls[i]; +// String requestURI = httpServletRequest.getRequestURI(); +// if (excludeUrl.equals(requestURI)) { +// // 放行请求 +// filterChain.doFilter(httpServletRequest, httpServletResponse); +// return; +// } +// } +// // 排除请求 +// HttpSession session = httpServletRequest.getSession(); +// Object user = session.getAttribute("user"); +// if (user == null) { +// // 当前用户没有登录或者登录会话失效 +// // 重定向到登录页面 +// httpServletResponse.sendRedirect(contextPath+"/"); +// return; +// } +// // 用户已经登录了 正常放行请求 +// filterChain.doFilter(httpServletRequest, httpServletResponse); +// } +//} +// diff --git a/src/com/landaiqing/service/AdminUserService.java b/src/com/landaiqing/service/AdminUserService.java index d808d99..9a92bd8 100644 --- a/src/com/landaiqing/service/AdminUserService.java +++ b/src/com/landaiqing/service/AdminUserService.java @@ -21,4 +21,48 @@ public class AdminUserService { public ArrayList selectAllAdmin() { return adminUserDao.selectAllAdmin(); } + + /** + * 修改管理员的状态 + * */ + public int OpenAdmin(Integer id){ + return adminUserDao.OpenAdmin(id); + } + + /** + * 关闭管理员的状态 + * */ + public int CloseAdmin(Integer id){ + return adminUserDao.CloseAdmin(id); + } + + /** + * 通过ID查询管理员 + */ + public AdminUserEntity getAdminByID(Integer id) { + return adminUserDao.getAdminByID(id); + } + + /** + * 修改管理员信息 + */ + public int updateAdmin(AdminUserEntity userEntity) { + return adminUserDao.updateAdmin(userEntity); + } + + /** + * 添加管理员 + * */ + + public int insertAdmin(AdminUserEntity adminUserEntity){ + return adminUserDao.insertAdmin(adminUserEntity); + } + + /** + * 删除管理源 + * */ + + public int deleteAdmin(Integer id){ + return adminUserDao.deleteAdmin(id); + } } diff --git a/src/com/landaiqing/servlet/system/AddAdmin.java b/src/com/landaiqing/servlet/system/AddAdmin.java new file mode 100644 index 0000000..d4469fd --- /dev/null +++ b/src/com/landaiqing/servlet/system/AddAdmin.java @@ -0,0 +1,61 @@ +package com.landaiqing.servlet.system; + +import com.landaiqing.entity.AdminUserEntity; +import com.landaiqing.service.AdminUserService; +import com.landaiqing.service.UserService; +import com.mysql.cj.util.StringUtils; +import jakarta.servlet.ServletException; +import jakarta.servlet.annotation.WebServlet; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +import java.io.IOException; +import java.util.Date; + +@WebServlet("/addAdmin") +public class AddAdmin extends HttpServlet { + private AdminUserService adminUserService=new AdminUserService(); + @Override + protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + try { + + String adminUseName = req.getParameter("adminUserName"); + if (StringUtils.isNullOrEmpty(adminUseName)){ + req.setAttribute("errorMsg","adminUseName 的值不能为空!!!"); + req.getRequestDispatcher("error.jsp").forward(req,resp); + return; + } + String adminPassword = req.getParameter("adminPassword"); + if (StringUtils.isNullOrEmpty(adminPassword)){ + req.setAttribute("errorMsg","adminPassword 的值不能为空!!!"); + req.getRequestDispatcher("error.jsp").forward(req,resp); + return; + } + String isValid = req.getParameter("isValid"); + if (StringUtils.isNullOrEmpty(isValid)){ + req.setAttribute("errorMsg","isValid 的值不能为空!!!"); + req.getRequestDispatcher("error.jsp").forward(req,resp); + return; + } + + + AdminUserEntity adminUserEntity=new AdminUserEntity(); + adminUserEntity.setAdminUserName(adminUseName); + adminUserEntity.setAdminPassword(adminPassword); + adminUserEntity.setIsValid(Integer.valueOf(isValid)); + + int result = adminUserService.insertAdmin(adminUserEntity); + if (result<=0){ + req.setAttribute("errorMsg","插入失败!!!"); + req.getRequestDispatcher("error.jsp").forward(req,resp); + return; + } + resp.sendRedirect("./System/index.jsp"); + } catch (Exception e) { + req.setAttribute("errorMsg","系统异常!!!"); + req.getRequestDispatcher("error.jsp").forward(req,resp); + throw new RuntimeException(e); + } + } +} diff --git a/src/com/landaiqing/servlet/system/AllAdmin.java b/src/com/landaiqing/servlet/system/AllAdmin.java index 6988043..374a358 100644 --- a/src/com/landaiqing/servlet/system/AllAdmin.java +++ b/src/com/landaiqing/servlet/system/AllAdmin.java @@ -1,5 +1,6 @@ package com.landaiqing.servlet.system; +import com.alibaba.fastjson.JSONObject; import com.landaiqing.entity.AdminUserEntity; import com.landaiqing.service.AdminUserService; import jakarta.servlet.ServletException; @@ -9,10 +10,11 @@ import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import java.io.IOException; +import java.io.PrintWriter; import java.util.ArrayList; import java.util.List; -@WebServlet("/allAdmin") +@WebServlet("/adminList") public class AllAdmin extends HttpServlet { private AdminUserService adminUserService=new AdminUserService(); @Override @@ -23,8 +25,13 @@ public class AllAdmin extends HttpServlet { @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { List adminUserEntityList=adminUserService.selectAllAdmin(); - req.setAttribute("allAdmin",adminUserEntityList); - req.getRequestDispatcher("./System/index.jsp").forward(req,resp); + PrintWriter writer=resp.getWriter(); + String jsonString = JSONObject.toJSONString(adminUserEntityList); + System.out.println(jsonString); + writer.println(jsonString); + writer.close(); +// req.setAttribute("allAdmin",adminUserEntityList); +// req.getRequestDispatcher("./System/index.jsp").forward(req,resp); } } diff --git a/src/com/landaiqing/servlet/system/CloseAdmin.java b/src/com/landaiqing/servlet/system/CloseAdmin.java new file mode 100644 index 0000000..fcf3cd2 --- /dev/null +++ b/src/com/landaiqing/servlet/system/CloseAdmin.java @@ -0,0 +1,44 @@ +package com.landaiqing.servlet.system; + +import com.landaiqing.entity.AdminUserEntity; +import com.landaiqing.service.AdminUserService; +import com.mysql.cj.util.StringUtils; +import jakarta.servlet.ServletException; +import jakarta.servlet.annotation.WebServlet; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Date; + +@WebServlet("/closeAdmin") +public class CloseAdmin extends HttpServlet { + private AdminUserService adminUserService=new AdminUserService(); + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + try { + String idStr = req.getParameter("id"); + if (StringUtils.isNullOrEmpty(idStr)){ + req.setAttribute("errorMsg","id的值不能为空!!!"); + req.getRequestDispatcher("error.jsp").forward(req,resp); + return; + } + int result = adminUserService.CloseAdmin(Integer.valueOf(idStr)); + if (result<=0){ + req.setAttribute("errorMsg","修改失败!!!"); + req.getRequestDispatcher("error.jsp").forward(req,resp); + return; + } + PrintWriter writer=resp.getWriter(); + writer.println("修改成功!"); + writer.close(); + resp.sendRedirect(""); + } catch (Exception e) { + req.setAttribute("errorMsg","系统异常!!!"); + req.getRequestDispatcher("error.jsp").forward(req,resp); + throw new RuntimeException(e); + } + } +} diff --git a/src/com/landaiqing/servlet/system/DeleteAdmin.java b/src/com/landaiqing/servlet/system/DeleteAdmin.java new file mode 100644 index 0000000..85d65d6 --- /dev/null +++ b/src/com/landaiqing/servlet/system/DeleteAdmin.java @@ -0,0 +1,44 @@ +package com.landaiqing.servlet.system; + +import com.landaiqing.service.AdminUserService; +import jakarta.servlet.ServletException; +import jakarta.servlet.annotation.WebServlet; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +import java.io.IOException; + +@WebServlet("/deleteAdmin") +public class DeleteAdmin extends HttpServlet { +private AdminUserService adminUserService=new AdminUserService(); + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + String idStr = req.getParameter("id"); + if (idStr==null || idStr==""){ + req.setAttribute("errorMsg","ID的值不能为空!!!"); + req.getRequestDispatcher("error.jsp").forward(req,resp); + return; + } + + try { + Integer id = Integer.parseInt(idStr); + int result = adminUserService.deleteAdmin(id); + if (result > 0) { +// req.getRequestDispatcher("showFlight.jsp").forward(req,resp); + resp.sendRedirect("./System/index.jsp"); + + }else { + req.setAttribute("errorMsg","删除失败!!!"); + req.getRequestDispatcher("error.jsp").forward(req,resp); + } + } catch (NumberFormatException e) { + req.setAttribute("errorMsg","类型转换异常,id 不能转换成Int类型!!!"); + req.getRequestDispatcher("error.jsp").forward(req,resp); + e.printStackTrace(); + }catch (Exception e){ + req.setAttribute("errorMsg","系统异常!!!"); + req.getRequestDispatcher("error.jsp").forward(req,resp); + } + } +} diff --git a/src/com/landaiqing/servlet/system/GetAdminByID.java b/src/com/landaiqing/servlet/system/GetAdminByID.java new file mode 100644 index 0000000..0278c72 --- /dev/null +++ b/src/com/landaiqing/servlet/system/GetAdminByID.java @@ -0,0 +1,92 @@ +package com.landaiqing.servlet.system; + +import com.landaiqing.entity.AdminUserEntity; +import com.landaiqing.service.AdminUserService; +import com.mysql.cj.util.StringUtils; +import jakarta.servlet.ServletException; +import jakarta.servlet.annotation.WebServlet; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +import java.io.IOException; +import java.util.Date; + +@WebServlet("/updateAdmin") +public class GetAdminByID extends HttpServlet { + private AdminUserService adminUserService=new AdminUserService(); + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + String idStr = req.getParameter("id"); + if (idStr==null || idStr==""){ + req.setAttribute("errorMsg","ID的值不能为空!!!"); + req.getRequestDispatcher("error.jsp").forward(req,resp); + return; + } + try { + Integer id = Integer.parseInt(idStr); + AdminUserEntity adminUserEntity = adminUserService.getAdminByID(id); + if (adminUserEntity==null){ + req.setAttribute("errorMsg","id不存在!!!"); + req.getRequestDispatcher("error.jsp").forward(req,resp); + return; + } + req.setAttribute("adminByID",adminUserEntity); + req.getRequestDispatcher("./System/adminManage.jsp").forward(req,resp); + }catch (Exception e){ + req.setAttribute("errorMsg","系统异常!!!"); + req.getRequestDispatcher("error.jsp").forward(req,resp); + } + } + + @Override + protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + try { + String idStr = req.getParameter("id"); + if (StringUtils.isNullOrEmpty(idStr)){ + req.setAttribute("errorMsg","id的值不能为空!!!"); + req.getRequestDispatcher("error.jsp").forward(req,resp); + return; + } + Integer id = Integer.parseInt(idStr); + + String adminUserName = req.getParameter("adminUserName"); + if (StringUtils.isNullOrEmpty(adminUserName)){ + req.setAttribute("errorMsg","adminUserName 的值不能为空!!!"); + req.getRequestDispatcher("error.jsp").forward(req,resp); + return; + } + String adminPassword = req.getParameter("adminPassword"); + if (StringUtils.isNullOrEmpty(adminPassword)){ + req.setAttribute("errorMsg","adminPassword 的值不能为空!!!"); + req.getRequestDispatcher("error.jsp").forward(req,resp); + return; + } + String isValid = req.getParameter("isValid"); + if (StringUtils.isNullOrEmpty(idStr)){ + req.setAttribute("errorMsg","isValid 的值不能为空!!!"); + req.getRequestDispatcher("error.jsp").forward(req,resp); + return; + } + + + AdminUserEntity adminUserEntity=new AdminUserEntity(); + adminUserEntity.setAdminId(id); + adminUserEntity.setAdminUserName(adminUserName); + adminUserEntity.setAdminPassword(adminPassword); + adminUserEntity.setIsValid(Integer.valueOf(isValid)); + + int result = adminUserService.updateAdmin(adminUserEntity); + if (result<=0){ + req.setAttribute("errorMsg","修改失败!!!"); + req.getRequestDispatcher("error.jsp").forward(req,resp); + return; + } + resp.sendRedirect("./System/adminManage.jsp"); + } catch (Exception e) { + req.setAttribute("errorMsg","系统异常!!!"); + req.getRequestDispatcher("error.jsp").forward(req,resp); + throw new RuntimeException(e); + } + } +} diff --git a/src/com/landaiqing/servlet/system/OpenAdmin.java b/src/com/landaiqing/servlet/system/OpenAdmin.java new file mode 100644 index 0000000..89ae4fc --- /dev/null +++ b/src/com/landaiqing/servlet/system/OpenAdmin.java @@ -0,0 +1,44 @@ +package com.landaiqing.servlet.system; + +import com.landaiqing.entity.AdminUserEntity; +import com.landaiqing.service.AdminUserService; +import com.mysql.cj.util.StringUtils; +import jakarta.servlet.ServletException; +import jakarta.servlet.annotation.WebServlet; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Date; + +@WebServlet("/openAdmin") +public class OpenAdmin extends HttpServlet { + private AdminUserService adminUserService=new AdminUserService(); + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + try { + String idStr = req.getParameter("id"); + if (StringUtils.isNullOrEmpty(idStr)){ + req.setAttribute("errorMsg","id的值不能为空!!!"); + req.getRequestDispatcher("error.jsp").forward(req,resp); + return; + } + int result = adminUserService.OpenAdmin(Integer.valueOf(idStr)); + if (result<=0){ + req.setAttribute("errorMsg","修改失败!!!"); + req.getRequestDispatcher("error.jsp").forward(req,resp); + return; + } + PrintWriter writer=resp.getWriter(); + writer.println("修改成功!"); + writer.close(); + resp.sendRedirect(""); + } catch (Exception e) { + req.setAttribute("errorMsg","系统异常!!!"); + req.getRequestDispatcher("error.jsp").forward(req,resp); + throw new RuntimeException(e); + } + } +} diff --git a/web/System/adminManage.jsp b/web/System/adminManage.jsp index b048758..47901c5 100644 --- a/web/System/adminManage.jsp +++ b/web/System/adminManage.jsp @@ -9,8 +9,333 @@ Title + + + + + + - 管理员管理 + + + + + + + + + +
+ + + + + + + +