遇到过好几次空指针错误。
1、导入User实体时,没有将真正的User实体传入
2、参数写错,把
String username=request.getParameter(“username”);
String password=request.getParameter(“password”);
username和password打错,出现错误时,要注意错误的代码行,多利用debug观察参数值。
public ModelAndView doLogin(HttpServletRequest request) {
String username=request.getParameter("username");
String password=request.getParameter("password");
ModelAndView mv=new ModelAndView();
if(username.equals("张三")&&password.equals("123")) {
mv.setViewName("success");
mv.addObject("user","张三");
}else {
mv.setViewName("fail");
}
return mv;
}