Commit 526a064c by Patryk Czarnik

Lista produktów za pomocą JSP + klasa Bean

parent 8e83395d
package sklep.web;
import java.util.List;
import sklep.db.DBConnection;
import sklep.db.DBException;
import sklep.db.ProductDAO;
import sklep.model.Product;
public class ProductBean {
/* Ta klasa jest po to, aby w skrypcie JSP w wygodny sposó” odczytać sobie listę produktów z bazy danych. */
public List<Product> getAllProducts() throws DBException {
try(DBConnection db = DBConnection.open()) {
ProductDAO productDAO = db.productDAO();
return productDAO.readAll();
}
}
}
<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="jakarta.tags.core"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Lista produktów 5</title>
<link rel="stylesheet" type="text/css" href="styl.css">
</head>
<body>
<h1>Lista produktów - wersja 5</h1>
<jsp:useBean id="productBean" class="sklep.web.ProductBean"/>
<c:forEach var="product" items="${productBean.allProducts}">
<div class="product">
<h3>${product.productName}</h3>
<div>Cena: ${product.price}</div>
<c:if test="${not empty(product.description)}">
<p class="description">${product.description}</p>
</c:if>
</div>
</c:forEach>
</body>
</html>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment