diff --git a/src/com/hellogithub/dao/AdminDao.java b/src/com/hellogithub/dao/AdminDao.java index 9130b36..72b77bf 100644 --- a/src/com/hellogithub/dao/AdminDao.java +++ b/src/com/hellogithub/dao/AdminDao.java @@ -39,18 +39,16 @@ public class AdminDao { } } - public int updateAdminLoginTime(String name){ - String label=""; + public int updateAdminLoginTime(String adminName, String loginTime){ int num; try { Connection conn = JdbcUtils.getConnection(); QueryRunner runner = new QueryRunner(); - String sql="UPDATE user SET searchHistory = ? WHERE userName= ? and isValid = 1"; - num = runner.update(conn,sql,label,name); + String sql="UPDATE admin SET loginTime = ? WHERE adminName= ? and isValid = 1"; + num = runner.update(conn,sql,loginTime,adminName); } catch (SQLException e) { throw new RuntimeException(e); } - return num; } diff --git a/src/com/hellogithub/service/AdminService.java b/src/com/hellogithub/service/AdminService.java index 1ba09c0..a09fbb9 100644 --- a/src/com/hellogithub/service/AdminService.java +++ b/src/com/hellogithub/service/AdminService.java @@ -8,7 +8,14 @@ public class AdminService { AdminDao adminDao=new AdminDao(); public adminEntity adminLogin(String userName, String password,String loginTime){ - return AdminDao.AdminLogin(userName,password,loginTime); + int num=adminDao.updateAdminLoginTime(userName,loginTime); + if(num==1){ + return AdminDao.AdminLogin(userName,password,loginTime); + } + else { + return null; + } + } } diff --git a/src/com/hellogithub/servlet/systemAdmin/AdminLoginServlet.java b/src/com/hellogithub/servlet/systemAdmin/AdminLoginServlet.java index 20fd413..ca3b091 100644 --- a/src/com/hellogithub/servlet/systemAdmin/AdminLoginServlet.java +++ b/src/com/hellogithub/servlet/systemAdmin/AdminLoginServlet.java @@ -16,6 +16,9 @@ import org.apache.commons.lang3.StringUtils; import javax.servlet.http.Cookie; import java.io.IOException; import java.io.PrintWriter; +import java.text.SimpleDateFormat; +import java.time.LocalDateTime; +import java.util.Date; import java.util.HashMap; @WebServlet("/adminLogin") @@ -23,7 +26,7 @@ public class AdminLoginServlet extends HttpServlet { AdminService adminService=new AdminService(); @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { - doGet(req, resp); + doPost(req, resp); } @Override @@ -46,7 +49,6 @@ public class AdminLoginServlet extends HttpServlet { setResultError("用户名不能够是为空!", writer); return; } - String adminPwd = req.getParameter("password"); // 参数验证 if (StringUtils.isEmpty(adminPwd)) { @@ -54,13 +56,10 @@ public class AdminLoginServlet extends HttpServlet { setResultError("密码不能够是为空!", writer); return; } - - String loginTime=req.getParameter("loginTime"); - if (StringUtils.isEmpty(loginTime)){ - //转发到错误页面 - setResultError("登陆时间不能够是为空!", writer); - return; - } + Date now = new Date(); + SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + String loginTime=sdf.format(now); + System.out.println(loginTime); // 从session中获取图形验证码 HttpSession session = req.getSession();