曾经做没有任何附加功能的登录功能时没有这种情况,结合了MD5和撒盐后就出问题了,报的错如图所示:
目前登陆方法的代码:
@RequestMapping("/dologin")
public String login(HttpServletRequest request, Model model,HttpSession httpSession) {
String userName = request.getParameter("userName");
String password = request.getParameter("password");
User user = userService.FindNameAndPsw(userName, password);
model.addAttribute("user", user);
List<Lost> listLostAll = lostService.findAllByOrderByLostDateDesc();
List<Lost> top5Lost = listLostAll.subList(0, 5);
List<Found> listFoundAll = foundService.findAllByOrderByFoundDateDesc();
List<Found> top5Found = listFoundAll.subList(0, 5);
model.addAttribute("top5Lost",top5Lost);
model.addAttribute("top5Found",top5Found);
String str = "";
String salt = "lyy2love1kenny3";
PasswordEncoder encoderMd5 = new PasswordEncoder(salt, "MD5");
password = encoderMd5.encode(password);
//密码匹配成功
if(user.getPassword().equals(password)){
System.out.println("登陆成功");
str = "success";
httpSession.setAttribute("user", user);
}
//密码错误
else{
System.out.println("密码错误");
str = "login";
}
return str;
}
曾经不会出问题的登陆方法:
@RequestMapping("/dologin")
public String login(HttpServletRequest request, Model model,HttpSession httpSession) {
String userName = request.getParameter("userName");
String password = request.getParameter("password");
User user = userService.FindNameAndPsw(userName, password);
model.addAttribute("user", user);
System.out.println(user);
String str = "";
if (user != null ) {
str = "success";
httpSession.setAttribute("user", user);
} else {
str = "login";
System.out.println("用户不存在");
}
return str;
}
请问可能是什么原因会导致每次重启项目都报空指针的错呢?
我看网上有的资料说是MySQL的8小时连接问题,一个connection空闲超过8个小时,Mysql将自动断开。可我在几分钟内重启项目,都会再次报空指针,不像别人的遇到的问题是“每天启动的第一次会报空指针”,所以先排除了MySQL的8小时原因,怀疑自己登陆方法写错了,可是我看不出哪有错……求大佬们指点