我想在Spring MVC中使用弹出窗口登录。我使用bootstrap。所以我可以打开popup.But当我启动app时,我得到“BindingResult或bean名称'loginModel'的普通目标对象可用作请求属性“error.login.jsp是我在index.jsp页面中包含的弹出窗口。
<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 :(得分: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。