2015-12-14 92 views
0

我想在彈出窗口中使用Spring MVC.I使用bootstrap。因此,我可以打開popup.But當我啓動應用程序時,我得到了「BindingResult或bean名稱的簡單目標對象」loginModel '可作爲請求屬性「error.login.jsp是一個彈出窗口,包含在我的index.jsp頁面中。彈出式MVC登錄彈出式窗口

<body> 
<form:form method="post" action="login" modelAttribute="loginModel"> 
    <table> 
     <tr> 
      <td>Kullanıcı Adı:</td> 
      <td><form:input type="text" path="username" /></td> 
      <td><form:errors path="username" cssClass="red" /></td> 
     </tr> 
     <tr> 
      <td>Şifre:</td> 
      <td><form:input type="password" path="password" /></td> 
      <td><form:errors path="password" cssClass="red" /></td> 
     </tr> 
    </table> 
    <input type="submit" /> 
    <input type="reset" /> 
</form:form> 
</body> 

這裏是我的控制器類;

@Controller 
public class LoginPageController { 

@RequestMapping(value = "/popupPages/login", method = RequestMethod.GET) 
public ModelAndView displayLogin(HttpServletRequest request, 
    HttpServletResponse response) { 
ModelAndView model = new ModelAndView("login"); 
model.addObject("loginModel", new LoginModel()); 
return model; 
} 

@RequestMapping(value = "/popupPages/login", method = RequestMethod.POST) 
public ModelAndView actionLogin(HttpServletRequest request, 
    HttpServletResponse response, 
    @ModelAttribute("loginModel") LoginModel loginModel) { 
ModelAndView model = new ModelAndView(); 
String username = loginModel.getUsername(); 
String password = loginModel.getPassword(); 
if (username.isEmpty() || password.isEmpty()) { 
    model.addObject("error", "Kullanıcı adı veya şifre boş geçilemez!"); 
} else { 
    // TODO: Bu kısımda kontrol yapılacak olup kontrole göre yönlendirme 
    // yapılacaktır. 
} 
return model; 
} 

}

有什麼錯?

回答

0

嘗試使用以下

@RequestMapping(value = "/popupPages/login", method = RequestMethod.GET) 
public String displayLogin(HttpServletRequest request, HttpServletResponse response) { 
    return "login"; 
} 


@RequestMapping(value = "/popupPages/login", method = RequestMethod.POST) 
public ModelAndView actionLogin(HttpServletRequest request, HttpServletResponse response, LoginModel loginModel) { 

而且,你的JSP應該像

<body> 
    <form:form method="post" action="${pageContext.request.contextPath}/popupPages/login" commandName="loginModel"> 
    ----- 
    </form:form> 
</body> 

對於信息敬請閱讀this

+0

我得到了同樣的錯誤。 – emreturka

+0

我編輯了我以前的答案。 @emreturka –

+0

我又得到了同樣的錯誤 – emreturka