2013-02-08 72 views
0

我是Spring MVC中的新成員,並且遇到問題。從jsp-form獲取地圖彈簧

我發送到FORM LinkedHashMap,它顯示很好。我的jsp

model.addAttribute("resultForm", resultForm); 

部分:

<c:forEach items="${resultForm}" var="resultMap" varStatus="status"> 
         <tr id="tableRow" class="table-row"> 
          <td> 
           ${resultMap.key} 
          </td> 
          <td> 
          <select name="resultMap['${resultMap.key}']" class="espa-config-select"> 
           <option selected value ="${resultMap.value}">${resultMap.value}</option> 
           <c:forEach items="${mainParams}" var="item2"> 
            <c:if test="${item2.key == resultMap.key}"> 
             <c:forEach items="${item2.value}" var = "q"> 
              <c:if test="${resultMap.value != q}"> 
               <option value="${q}"> ${q} </option> 
              </c:if> 
             </c:forEach> 
            </c:if> 
           </c:forEach> 
          </select> 
          </td> 
         </tr> 
        </c:forEach> 

現在我需要把它找回來

這裏是控制器

@RequestMapping(value = "espa/update", method = RequestMethod.POST) 
    public String save(@ModelAttribute("resultForm") LinkedHashMap<String,String> resultForm) { 
     System.out.println("resultMap post "+resultForm.toString()); 
     if (resultForm!=null){ 
      //resultForm.put("Port", port); 
      espaService.setConfiguration(selectedDevice, resultForm); 
      LOG.debug("Saving configuration: {} /nPort{}",resultForm, selectedDevice); 

     } 

     return "redirect:/espa"; 
    } 

的一部分,但它是空的! 我該如何解決它?

+0

請重新表達你的問題,我聽不懂一個字。 – 2013-02-08 12:45:56

+0

也請添加一些示例代碼。 – gaborsch 2013-02-08 12:49:47

+0

更改問題並添加了一些代碼 – RIO 2013-02-08 13:07:59

回答

0

在您的選擇中,您正在使用名稱「resultMap」。名稱屬性需要與模型屬性相關聯,您將其稱爲「resultForm」。

+0

忘了提及,因爲我看不到整個JSP,或者至少是整個標籤,所以很難告訴你要完成什麼。此外,您可能會發現使用Spring MVC提供的JSTL標記更容易。 – CodeChimp 2013-02-09 02:14:39