【问题标题】:how to populate a drop down list from the database using iterator? jsp如何使用迭代器从数据库中填充下拉列表? jsp
【发布时间】:2013-05-06 18:15:53
【问题描述】:

我正在尝试使用我的数据库中的汽车类型填充下拉列表, 我已经对另一个 jsp 页面上的列表执行此操作,但是现在当我想对下拉列表执行相同操作时,它不起作用。 我可以看到它在数据库上的表上移动,因为在我的下拉列表中,我得到了 3 个空格。 (我的桌子目前包含 3 辆车)。

<jsp:useBean id="vs" scope="request" type="java.util.List" />
.
.
.
<tr>
    <td style="color:red; font-weight:bold">Vehicle:  </td
      <td> <select name= "vehicles" style="width: 100px">
           <% 
              Iterator it = vs.iterator();
              while (it.hasNext()) {
                   Vehicles vehicles = (Vehicles) it.next();
            %>
            <option value= <%=vehicles.getId()%> ${vehicles.getMake()} </option>
            <% } %>
            </select>         
      </td>
</tr>
.
.
.

提前致谢!

【问题讨论】:

    标签: jsp


    【解决方案1】:

    替换

     <option value= <%=vehicles.getId()%> ${vehicles.getMake()} </option>
    

    <option value= <%=vehicles.getId()%>><%={vehicles.getMake()%> </option>
    

    【讨论】:

    • 你在 getId()% 之后有一个额外的 '>',而在 getMake()% 之后缺少关闭 '}',不是吗?无论如何,不​​管有没有,仍然无法正常工作。
    • 好的,我知道了。只有'{'是额外的,现在工作!非常感谢!
    猜你喜欢
    • 1970-01-01
    • 2011-02-23
    • 2021-07-29
    • 1970-01-01
    • 2011-11-09
    • 2014-12-25
    相关资源
    最近更新 更多