我有一个由数据库填充的下拉菜单。下拉菜单中有与每个项目相关的图像。我要在选择下拉菜单时显示图像。
这是我的jsp代码。
<tr>
<td>Alloy Wheel:</td>
<%
try {
dbConnect dbConnect = new dbConnect();
Connection currentCon = dbConnect.Connect();
String sql = "SELECT * FROM alloywheel";
PreparedStatement ps = currentCon.prepareStatement(sql);
ResultSet rs = ps.executeQuery();
String img = rs.getString("alloy_image");
%>
<td>
<select class="form-control" name="alloy">
<option value="0">Select your alloywheel design</option>
<%
while (rs.next()) {
int aid = rs.getInt("alloy_id");
String aname = rs.getString("alloy_color");
int aprice = rs.getInt("alloy_price");
%>
<option value="<%=aid%>"><%=aname%> : <%=aprice%></option>
<%
}
%>
</select>
<%
} catch (Exception e) {
system.out.println(e);
}
%>
</td>
<td>
The image should be displayed here
</td>
</tr>
<tr>
<td colspan="3">
<button class="btn btn-success form-control">
Add to the cart
</button>
</td>
</tr>