Hi guys,
THE SITUATION:
I am following an example in a college text book.
The example is a simple web application for a online bakery.
Basically, you have a jsp showing a selection of baked goods which have been read from a database.
If you click on one of those items (which is a hyperlink), it adds the name of that item to
a 'cartBean' bean and reloads the page to display a table (the Cart) with the newly chosen item inside.
New items can be added to the cart in the same way, and the cart will accumulate all your chosen items.
Its really very simple.
Now, the example suggests (and I presume) that the only way to ensure the cartBean keeps
its contents (without being emptied) is to ensure that the scope="session"/"application".
If scope="page" is specified, a new bean instance will be created every time an item is added
to the cart meaning that there will only ever be max 1 item in the cart at all times.
THE PROBLEM:
Since the cartBeans scope needs to = "session", it means that the same cartBean
session is shared between multiple users! So, if user A loads the web page, and adds three items
to their cart, and then user B loads the web page, user B will see those three items have already
been loaded into their cart even though their cart should be empty.
I understand that bean sharing may be useful (at times), but in this case it is not what I'm looking for.
WHAT I'M LOOKING FOR:
I want a new bean instance to be created for each user. Furthermore, is it possible to destroy that
bean instance when a user leaves the web site?
I sincerely apologise if this has been covered before. If so, please forward me in the right direction.
Thanks