我是Spring MVC的新手,我正试图从控制器获取jsp表单选择列表的值。 显示选择列表,但它为空。我尝试了不同的例子等,但仍然找不到,问题出在哪里。
控制器:
@Controller
public class MainController {
@RequestMapping(value = "/", method = RequestMethod.GET)
public ModelAndView login() {
return new ModelAndView("login", "command", new Person());
}
@RequestMapping(value = "/", method = RequestMethod.POST)
public String login(@ModelAttribute("xxx")Person person, ModelMap model) {
Map<String,String> list = new LinkedHashMap<String,String>();
list.put("opt1", "value1");
list.put("opt2", "value2");
model.put("list", list);
return "newView";
}
}
newView.jsp:
<form:form method="POST" action="/xxx/saveUser" command="">
<table>
<tr>
<form:select path="name">
<form:options items="${list}" />
</form:select>
</tr>
</table>
</form:form>
Person.java模型:
public class Person {
private String name;
//Getters and setters and more values etc...
}
提前致谢