【发布时间】:2011-11-25 04:04:22
【问题描述】:
我在尝试实现我的第一个 spring+hibernate web 应用程序时遇到了以下异常:
java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'userProfile' available as request attribute
at org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:141)
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getBindStatus(AbstractDataBoundFormElementTag.java:174)
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getPropertyPath(AbstractDataBoundFormElementTag.java:194)
at org.springframework.web.servlet.tags.form.LabelTag.autogenerateFor(LabelTag.java:129)
...
用户控制器.java:
@Controller
public class UserController {
@Autowired
private UserProfileService userProfileService;
public UserController(){
}
@RequestMapping(value="/add", method=RequestMethod.POST)
public String registerUser(@ModelAttribute("userProfile") UserProfile userProfile, BindingResult result, Map model){
userProfileService.addUserProfile(userProfile);
return "redirect:/login";
}
...
}
UserProfile.java
@Entity
@Table(name="USER_PROFILE")
public class UserProfile {
@Id
@GeneratedValue
@Column(name = "ID")
private Long id;
@Column(name = "USERNAME")
private String userName;
@Column(name = "PASSWORD")
private String password;
//sets and gets
}
index.jsp
<form:form method="post" action="add" commandName="userProfile">
<table>
<tr>
<td><form:label path="userName"><spring:message code="label.username" /></form:label></td>
<td><form:input path="userName" /></td>
</tr>
<tr>
<td><form:label path="password"><spring:message code="label.password" /></form:label></td>
<td><form:password path="password" /></td>
</tr>
<tr>
<td><input type="submit" value="<spring:message code="label.adduser" />"></td>
</tr>
</table>
</form:form>
【问题讨论】:
标签: java hibernate spring exception