Hi guys,
I am learning how sessions work in the browser by using a very simple shopping cart application. I have a button that calls the following
servlet which then adds an item (a simple
string from a textfield on the webpage) to the shopping cart:
I then forward to a page that tells me what item I have just added. I then click the back button on the browser and can add another item.
My problem is that I have another button (on the same page where I can add items) to display all the items in the cart. This button takes me to another page but it only displays the last item I entered. Say I enter crisps, chocolate and fudge, fudge will only show up. Here is the code for that servlet:
Since I can read the last item I don't know if I am re-instantiating the shopping cart every time I call the servlet that adds the item. The shopping carts 'addItem' method simply adds a 'shoppingCartItem' (which has a String variable called name) to an ArrayList of items in the shopping cart. What am I doing wrong here?
Thanks,
Alan