Commit 6a2446ae by Patryk Czarnik

koszyk za pomocą sesji

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