1
返回值我是一個老的servlet/HTML的傢伙。我知道這應該是如此直截了當,但我無法找到什麼,我試圖做一個例子。也許我的方法是錯誤的,但希望得到一些建議。Spring MVC的形式不是從下拉列表中
我能夠使用彈出窗體標籤加載一個下拉列表,其中列表<>我從表格中檢索到的鍵值和值,但是當提交表單時,我得到一個EMPTY列表<>(size = 0 )。我能夠從表單中檢索答案(input = text)。
我位指示:jsp中的
@RequestMapping(value = "/getQuestions", method = RequestMethod.GET)
public ModelAndView getQuestionsPage() {
List<Question> questionsList = questionDAO.getAll();
return new ModelAndView("questions", "questionsList", questionsList);
}
@RequestMapping(method = RequestMethod.POST)
public ModelAndView processForm(@ModelAttribute("answer1") String answer1, @ModelAttribute("questionsList") java.util.ArrayList question) {
ModelAndView model = new ModelAndView("home");
return model;
}
表單部分:
<form action="questions" method="post" modelAttribute="questionsList">
<table>
<tr>
<td>Questions :</td>
<td><form:select path="questionsList">
<form:option value="0" label="Select" />
<form:options items="${questionsList}" itemValue="id" itemLabel="question" />
</form:select>
</td>
</tr>
<tr>
<td>Answer :</td>
<td><input type="text" name="answer1"></td>
<tr>
<td><input type="submit" /></td>
</tr>
</table>
我想它可能有一些做的?
任何幫助將不勝感激!