我收到以下错误 - java.lang.IllegalStateException:既没有BindingResult也没有bean名称的明确目标对象'命令'可用作请求属性
我试图搜索网络,但解决方案没有解决这个问题。
请找我的控制器类
@Controller
public class LoginController {
@RequestMapping(value = "/login",method=RequestMethod.GET)
public String showLoginPage(Model model) {
model.addAttribute("login", new LoginBean());
return "login";
}
}
login.jsp文件
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<body>
<h2>Information</h2>
<form:form method="POST">
<table>
<tr>
<td><form:label path="emailId">Name</form:label></td>
<td><form:input path="emailId" /></td>
</tr>
<tr>
<td><form:label path="password">Age</form:label></td>
<td><form:input path="password" /></td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="Submit" /></td>
</tr>
</table>
</form:form>
</body>
</html>
LoginBean.java类
public class LoginBean {
public LoginBean() {
}
private String emailId;
private String password;
public LoginBean(String emailId, String password) {
this.emailId = emailId;
this.password = password;
}
public String getEmailId() {
return emailId;
}
public void setEmailId(String emailId) {
this.emailId = emailId;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
任何帮助都将受到高度赞赏。请帮助。
答案 0 :(得分:2)
我想你应该在JSP中的表单中添加以下commandName属性:
<form:form method="POST" commandName="login">
<table>
<tr>
<td><form:label path="emailId">Name</form:label></td>
<td><form:input path="emailId" /></td>
</tr>
<tr>
<td><form:label path="password">Age</form:label></td>
<td><form:input path="password" /></td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="Submit" /></td>
</tr>
</table>
</form:form>
因为弹簧形式不能理解你引用的对象。