Designing a shopping cart with a stateful session bean
I found a solution, but it is very inelegant:
The servlet has alzheimer and does not remember the refernce variable of the stateful session bean after a refresh. So you have to save the reference in a HttpSession variable.
The stateful session Bean in wich the state of intMemory should be preserved:
The client Servlet reads the Value of intMemory and adds 10 to it. If yo do not save the reference to the Bean the value will stay 10. If you uncomment the blocks and comment out
NewSessionBean newSessionBean = lookupNewSessionBeanBean();
it works as expected, the values of the intMemory variables are as expected 10, 20, 30....
It ist still not time to
First: Suppose I have 2 catalogs with goods and one cart (which is the stateful session bean). If the reference to the stateful session bean is unique, it would not be possible to save values from two catalogs (i.e. servlet clients) to the one single bean. The shop could have only one catalog or the reference has to be promoted to another catalog, i.e. in a session
Second: The above solution where the reference variable of the stateful session bean is saved in a HttpSession seems inelegant, somebody knows a better solution?
Third: Can the variable intMemory be an int instead an Integer and still be preserved? (you usually can only save Objects in a session, but here an int is a compound of an object, I will try and report).