我取出由DB圖像src
,並試圖把它變成JSP頁面,但只有一個圖像加載和休息2圖像不加載無法遍歷從數據庫
代碼:
<%
Iterator<product> itr = list.iterator();
while(itr.hasNext())
{
p=itr.next();
String price=p.getPrice();
String img=p.getImg();
String pname=p.getPname();
%>
<script>
document.getElementById("image").src="<%=img %>";
</script>
<div class="item">
<img src="" alt="<%=img%>" id="image"/>
<h2><%=pname%></h2>
<p>Price: <em>Rs <%=price%></em>
</p>
<button class="add-to-cart" type="button">Add to cart</button>
</div>
<% } %>
但我得到下面的輸出:
的Java DB代碼:
public List<product> getProducts(String brand)
{
List<product> prod=new ArrayList<product>();
try
{
conn = obj.connect();
String sql="select product.product_name , product.price , product.image_url "
+ "from category , product "
+ "where product.category_id=category.category_id and product.product_brand like 'LG%'";
cs=conn.createStatement();
rs=cs.executeQuery(sql);
while(rs.next())
{
product p=new product();
p.setPname(rs.getString(1));
p.setPrice(rs.getString(2));
p.setImg(rs.getString(3));
prod.add(p);
}
}
catch(SQLException e)
{
e.printStackTrace();
}
catch(Exception k)
{
k.printStackTrace();
}
return prod;
}
}
你真的應該有[這]讀(http://stackoverflow.com/q/3177733/3419894) – JonK
@ xrcwrn完成.. –
@JonK ..我一定會讀這個..感謝很多 –