【发布时间】:2015-11-07 06:13:00
【问题描述】:
我有一个register.jsp 页面,我将以下数据绑定到一个modelAttribute userform。
<form:form method="post" modelAttribute="userform"
enctype="multipart/form-data" autocomplete="off" class="form">
<spring:bind path="firstName">
<label>First Name: </label>
<form:input path="firstName" placeholder="First Name" />
</spring:bind>
<spring:bind path="lastName">
<label class="control-label">Last Name: </label>
<form:input path="lastName" placeholder="Last Name" />
</spring:bind>
</form:form>
控制器上的 get 和 post 方法在哪里:
@RequestMapping(value = "/register", method = RequestMethod.GET)
public String register(@ModelAttribute("userform") Employee employee, Model model) {
List<Role> roleList = roleService.getAllList();
model.addAttribute("roleList", roleList);
model.addAttribute("userform", employee);
return "employee/register";
}
@RequestMapping(value = { "/register" }, method = RequestMethod.POST)
public String processRegistration(@Valid @ModelAttribute("userform") Employee employee, BindingResult result,
Model model, HttpServletRequest request) throws IllegalStateException, IOException {
//(expecting the data from jsp) nothing in the employeee object :(
//dosomething
return "employee/register";
}
虽然我使用了相同的名称userform,并且实体Employee 上的属性名称完全相同,但我无法将表单数据从JSP 获取到Controller。我一定在这里做错了,但找不到。任何帮助将不胜感激。
【问题讨论】:
-
你用的是什么版本的spring??
标签: java spring jsp spring-mvc