I'm trying to make an if in a jsp file, but I can not print all the values that are in the products table. For some reason my code only prints the first product and in the table I have 3 products.
<c:forEach items="${products}" var="product">
<div class="w3-col l3 s4" style="width: 25rem;">
<div class="w3-container">
<img src="/w3images/" style="width:80%">
${product.productName}
</div>
<div class="w3-container">
<h5 class="card-title">${product.productPrice}</h5>
<p class="card-text">${product.productDescription}</p>
<input id="productId" name="productId" type="hidden" value="${product.productId}">
<button type="submit" class="w3-button w3-black" >Bid</button>
<br>
</div>
</div>
</c:forEach>
My backend:
private ProductService productService = new ProductService();
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String product_name = request.getParameter("userSearch");
List<Product> productList = productService.searchProductName(product_name); //get product by name
request.setAttribute("products", productList);
request.getRequestDispatcher("/WEB-INF/views/userAds.jsp").forward(request, response);
System.out.println(productList);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String userSearch = request.getParameter("userSearch");
List<Product> productList = productService.searchProductName(userSearch); //get product by name
request.setAttribute("products", productList);
request.getRequestDispatcher("/WEB-INF/views/userAds.jsp").forward(request, response);
}
}