2016-05-23 4 views
0

私はmysqlデータベースから車のリストをロードしようとしています。しかし、私のドロップダウンリストは空になっています。私のコードは以下の通りです。JSPの空のドロップダウン

<select> 
<c:forEach var="line" items="${cars}"> 
    <option><c:out value="${line}"/></option> 
</c:forEach> 
</select> 

<% 
ArrayList<CarsDataBean> cars = CarsDAO.getCars(); 
request.setAttribute("cars", cars.getCars()); 
%> 
+0

実際にデータを取得していることは確かですか? –

+0

はい、DAOが正常に動作しています。 getCars()は、carNameの4つの属性を返します。私が投入しようとしている価値はどれですか。 – neo

答えて

0

属性を使用する前に設定する必要があります。ここにデモンストレーションコードがあります。

<%@ taglib prefix = "c" uri = "http://java.sun.com/jsp/jstl/core" %> 
<c:set value="Ford,Chevy,Honda" var="vehicles" scope="request"/> 
The cars in the list are ${cars}. 
<% 
    request.setAttribute("cars", request.getAttribute("vehicles")); 
%> 
The cars in the list are ${cars}. 

出力:リストで
車があります。リストの車はフォード、シボレー、ホンダです。

関連する問題