Commit 6a2446ae by Patryk Czarnik

koszyk za pomocą sesji

parent 3776e632
...@@ -2,12 +2,12 @@ package sklep.basket; ...@@ -2,12 +2,12 @@ package sklep.basket;
import java.io.IOException; import java.io.IOException;
import javax.servlet.ServletContext;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet; import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import sklep.db.DBConnection; import sklep.db.DBConnection;
import sklep.db.ProductDAO; import sklep.db.ProductDAO;
...@@ -24,11 +24,11 @@ public class AddToBasket extends HttpServlet { ...@@ -24,11 +24,11 @@ public class AddToBasket extends HttpServlet {
ProductDAO productDAO = db.productDAO(); ProductDAO productDAO = db.productDAO();
Product product = productDAO.findById(id); Product product = productDAO.findById(id);
ServletContext context = this.getServletContext(); HttpSession session = request.getSession();
Basket basket = (Basket) context.getAttribute("basket"); Basket basket = (Basket) session.getAttribute("basket");
if(basket == null) { if(basket == null) {
basket = new Basket(); basket = new Basket();
context.setAttribute("basket", basket); session.setAttribute("basket", basket);
} }
basket.addProduct(product); basket.addProduct(product);
} }
......
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