I have a ShoppingCart class, that contains CartItems (in an ArrayList). What I want is that whenever a session exists (when user has added items to a cart), it should request fo
Just store it as an attribute of the session and check on every request if it is there.
HttpSession session = request.getSession();
Cart cart = (Cart) session.getAttribute("cart");
if (cart == null) {
cart = new Cart();
session.setAttribute("cart", cart);
}
cart.add(item);
// ...
You normally do this in a Servlet class. JSP should be used for presentation only.