管理员登录

This commit is contained in:
2023-07-08 18:54:05 +08:00
parent 4a337e2c40
commit b0e46ad33f
3 changed files with 19 additions and 15 deletions

View File

@@ -39,18 +39,16 @@ public class AdminDao {
} }
} }
public int updateAdminLoginTime(String name){ public int updateAdminLoginTime(String adminName, String loginTime){
String label="";
int num; int num;
try { try {
Connection conn = JdbcUtils.getConnection(); Connection conn = JdbcUtils.getConnection();
QueryRunner runner = new QueryRunner(); QueryRunner runner = new QueryRunner();
String sql="UPDATE user SET searchHistory = ? WHERE userName= ? and isValid = 1"; String sql="UPDATE admin SET loginTime = ? WHERE adminName= ? and isValid = 1";
num = runner.update(conn,sql,label,name); num = runner.update(conn,sql,loginTime,adminName);
} catch (SQLException e) { } catch (SQLException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
return num; return num;
} }

View File

@@ -8,7 +8,14 @@ public class AdminService {
AdminDao adminDao=new AdminDao(); AdminDao adminDao=new AdminDao();
public adminEntity adminLogin(String userName, String password,String loginTime){ public adminEntity adminLogin(String userName, String password,String loginTime){
int num=adminDao.updateAdminLoginTime(userName,loginTime);
if(num==1){
return AdminDao.AdminLogin(userName,password,loginTime); return AdminDao.AdminLogin(userName,password,loginTime);
} }
else {
return null;
}
}
} }

View File

@@ -16,6 +16,9 @@ import org.apache.commons.lang3.StringUtils;
import javax.servlet.http.Cookie; import javax.servlet.http.Cookie;
import java.io.IOException; import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
@WebServlet("/adminLogin") @WebServlet("/adminLogin")
@@ -23,7 +26,7 @@ public class AdminLoginServlet extends HttpServlet {
AdminService adminService=new AdminService(); AdminService adminService=new AdminService();
@Override @Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
doGet(req, resp); doPost(req, resp);
} }
@Override @Override
@@ -46,7 +49,6 @@ public class AdminLoginServlet extends HttpServlet {
setResultError("用户名不能够是为空!", writer); setResultError("用户名不能够是为空!", writer);
return; return;
} }
String adminPwd = req.getParameter("password"); String adminPwd = req.getParameter("password");
// 参数验证 // 参数验证
if (StringUtils.isEmpty(adminPwd)) { if (StringUtils.isEmpty(adminPwd)) {
@@ -54,13 +56,10 @@ public class AdminLoginServlet extends HttpServlet {
setResultError("密码不能够是为空!", writer); setResultError("密码不能够是为空!", writer);
return; return;
} }
Date now = new Date();
String loginTime=req.getParameter("loginTime"); SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
if (StringUtils.isEmpty(loginTime)){ String loginTime=sdf.format(now);
//转发到错误页面 System.out.println(loginTime);
setResultError("登陆时间不能够是为空!", writer);
return;
}
// 从session中获取图形验证码 // 从session中获取图形验证码
HttpSession session = req.getSession(); HttpSession session = req.getSession();