Commit 8fe808df by Patryk Czarnik

koszyk w sesji

parent 1f255ec0
......@@ -7,6 +7,7 @@ import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;
import sklep.db.DBConnection;
import sklep.db.ProductDAO;
import sklep.model.Product;
......@@ -23,17 +24,19 @@ public class AddToBasket extends HttpServlet {
ProductDAO productDAO = db.productDAO();
Product product = productDAO.findById(productId);
Basket basket = (Basket)getServletContext().getAttribute("basket");
HttpSession sesja = request.getSession();
Basket basket = (Basket)sesja.getAttribute("basket");
if(basket == null) {
basket = new Basket();
getServletContext().setAttribute("basket", basket);
sesja.setAttribute("basket", basket);
}
basket.addProduct(product);
}
} catch(Exception e) {
// ignorujemy błędy
}
// Przekierowanie - każemy przeglądarce wejść pod ten adres.
response.sendRedirect("products8.jsp");
}
}
......@@ -5,7 +5,7 @@
<html>
<head>
<meta charset="UTF-8">
<title>Lista produktów 7</title>
<title>Lista produktów 8</title>
<link rel="stylesheet" type="text/css" href="styl.css">
</head>
<body>
......
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