2017-02-09 48 views
0

我使用的是Spring MVC模型屬性方法。打開屏幕時,我必須閱讀JSON字符串並創建一個地圖。在下拉列表中顯示地圖。我可以看到HTML源代碼中的值,但看不到屏幕中的下拉菜單。春天mvc窗體:選擇選項不顯示在屏幕上但在HTML源代碼中

@RequestMapping("/xxx") 
public ModelAndView saws(Map<String, Object> model1) throws IOException { 
    ModelAndView model = new ModelAndView("xxx"); 
    model.addObject("message", this.welcome); 
    Map<String, String> offers = engine.getOffers(); 
    model.addObject("offers", offers);//map of offers 
    model.addObject("inputs", new inputs()); 
    return model; 

} 

JSP

<form:form action="getoffers" method="get" modelAttribute="inputs"> 
<body> 
<table align="center"> 
     <tr class="blank_row"> 
      <td colspan="2"></td> 
     </tr> 
     <tr class="blank_row"> 
      <td colspan="2"></td> 
     </tr> 
     <tr align="center"> 
      <th span 
       style="color: red; font-weight: bold; word-wrap: break-word;" 
       align="center">Select the service to view current offers</th> 
     </tr> 
     <tr> 
      <td><form:select path="offers"> 
        <form:options items="${offers}" /> 
       </form:select></td> 
     </tr> 
    </table> 

並且在屏幕我沒有看到下降down.when我檢查的源代碼我看到這一點。請看到的圖片

enter image description here

enter image description here

回答

1

假設你已經有了消費滿-MVC依賴。

html源文件不應該有<form:...>前綴。它沒有被正確渲染。

把這個在你的JSP文件:
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>

我強烈建議您使用Thymeleaf模板引擎而不是JSP。原因太長,無法適應此答案區域。

+0

spot on.that worked.Sure I'll into into thymeleaf – Shiv

+1

@Shiv不用客氣。這也是因爲你的問題有足夠的細節。 –

+0

感謝您的慷慨評論 – Shiv

相關問題