• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Stateful Session Bean - state??

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am having a hard time understanding SFSBs. I would like to maintain state in the EJB tier, but it doesn't seem to work that way when the browser is the ejb client. It looks like I have to create a SFSB and store a reference of that in the HTTPSession - is that correct?
For example, with the typical shopping cart example, a user adds a product to his cart. Then, jumps around the site to different pages and decides to add another product. This action should add a product to the same instance of Cart object that he used previously. I can only get this to work if I store a reference to the one SFSB instance in the HTTPSession.
If I don't do it this way, and instead get the SFSB by calling ejbCreate() each time a product is added to the cart, it gives me a newly instantiated Cart object. In other words, It doesn't contain the products that was added earlier...
I am totally confused because books/articles talk about using HTTPSession vs. SFSB for this purpose --- but they appear to me to serve different purposes entirely.
So, is using the HTTPSession to store the SFSB reference the only way to maintain ejb state across multiple page navigations (e.g. http requests).
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you're right on track. HTTPSession maintains web server state on behalf of the browser client, SFSB maintain app server state on behalf of the web server as client, so you're right about they are different things. The problem is that only one or two web server clients represent a lot of human users, and the app server can't keep them all straight without help. So the web server often gets a handle to the SFSB and stores the handle in its session. Then it can use the handle to relate a request to a user in a way that the app server understands. Zat make sense?
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic