user2355639
user2355639

Reputation: 25

how to populate a drop down list from the database using iterator? jsp

I'm trying to populate a drop down with types of cars from my database, I already secceed on doing this to a list on another jsp page, but now when I want to do the same to a drop down list, its not working. I can see that its moving over the table on the database because on my drop down list I'm getting 3 blank spaces. (my table contain 3 vehicles at the moment).

<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>
.
.
.

Thanks in advance!

Upvotes: 1

Views: 4822

Answers (1)

Alpesh Gediya
Alpesh Gediya

Reputation: 3794

replace

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

with

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

Upvotes: 1

Related Questions