0

我试图访问表单中包含的数据,但遇到空指针异常

这是我的表格:

<form:form action="dologin.htm"  method="post" commandName="loginform">
                          <content goes in here>

我正在使用的控制器:

@RequestMapping("/login") //login page
  public ModelAndView initLoginPage() {          
      Map<String, Object> model = new HashMap<String, Object>();
      model.put("loginform", new Login());

      return new ModelAndView("login", model);        
  }

@RequestMapping(value = "/dologin", method = RequestMethod.POST)
    protected ModelAndView logar(@ModelAttribute("loginform") Login loginForm, BindingResult result) {
    if(loginService.doLogin(loginForm)!= null){
        return new ModelAndView("home");
    }else{
        String error = "Make sure to fill in all fields";
        return new ModelAndView("login","error",error);
    }
}

Login 类包含与表单上相同的字段(用户名和密码)

4

0 回答 0