2012-05-08 91 views
2

我有這個代碼,它使用JSTL迭代通過ArrayList<String> towns = new ArrayList<String>();,但即使ArrayList沒有顯示任何空白條目,我仍然會收到交替的空白條目(每第2行),所以我不知道發生了什麼。foreach循環導致空白條目?

<c:if test="${!empty towns }"> 
    <select id="town"> 
     <c:forEach items="${towns}" varStatus="loop"> 
      <option value="${towns[loop.index]}">${towns[loop.index]}<option> 
     </c:forEach> 
    </select> 
</c:if> 

回答

4

應該</option>就結束。

0

試試這個:

<c:if test="${!empty towns}"> 
    <select id="town"> 
     <c:forEach var="t" items="${towns}"> 
      <option value="${t}">${t}<option> 
     </c:forEach> 
    </select> 
</c:if> 
+0

沒有工作,謝謝你的努力。 :( – Michael