Recently, I am trying to write shopping cart with Java session. I use List object to store products and then store in the session. When the user change the amount of the product is changed, I use the code below try to update the session. And it does work, cause when I refresh my page the number showing next to the cart icon is changed, but I really don't know how it works. Can anyone help me please ;/ ?
Here's the code when the user cancel a sprcific product, and I just remove from the list:
List<OrderProduct> orderProductList = (ArrayList<OrderProduct>)session.getAttribute("orderProductList");
for (int i = 0; i < orderProductList.size(); i ++) {
if (orderProductList.get(i).getProduct().getId() == productID) {
orderProductList.remove(i);
}
}
My problem is I did not do this
session.setAttribute(...)
but when I retrieve session in the jsp, the object stored in the session is changed, how does it works?