我嘗試根據資料庫上可用的值回圈遍歷一個專案,但我的索引頁面顯示為空白。請問有什么可能因為這個..我已經在mysql資料庫中插入了值。但它不能出現在索引頁面上
我的索引頁代碼:
<c:forEach var="p" items="${products}">
<jsp:useBean id="p" class="com.testing.products.Products"/>
<div class=" col-md-6 features15-col-text">
<div class="d-flex feature-unit align-items-center">
<div class="col-4">
<div class="features15-info">
<img class="img-fluid" src="" alt=" ">
</div>
</div>
<div class="col-8">
<div class="features15-para">
<h6>${p.price}</h6>
<h4>${p.productName}</h4>
<p>Ras effic itur metusga via suscipit</p>
<button type="button" class="btn btn-success w-50 touch" data-toggle="modal"
data-backdrop="static" data-keyboard="false" data-target="#easy" >buy</button>
</div>
</div>
</div>
</div>
</c:forEach>
這是我的 servlet 代碼
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
response.setContentType("text/html;charset=UTF-8");
try
{
List<Products> products = ProductDAO.getAllProducts();
request.setAttribute("products", products);
}
catch(Exception xcp)
{
}
}
uj5u.com熱心網友回復:
我猜你錯過了 JSTL 庫的匯入。
因此<c:forEach>,它實際上什么都不做,它不會在串列中回圈,也不會在p.
添加匯入應該可以解決問題:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<c:forEach var="p" items="${products}" >
${p.productName} - ${p.price}
</c:forEach>
請注意,該<jsp:useBean ...>行是無用的,應該洗掉。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/504195.html
