1

One typical example of using a Stateful Session Bean is through a ShoppingCart example. We create a bean instance of the ShoppingCart class, then store this instance within a HttpSession. However, the same can be achieved easily with the ShoppingCart class being a normal Java class (or a stateless session bean). A request of adding a product comes in, we create a cart object, then put that cart object inside a HttpSession.

So, I don't see the point of using a stateful session bean ShoppingCart here. And in general, a stateful session bean doesn't seem to play any significant roles.

echipbk
  • 21
  • 2

1 Answers1

0

I would rephrase your question:

  • Why should I use mechanism for automatic session based bean management (maintaining one instance per session, persisting inside session) if I can implement it myself?

Yes, you can implement it yourself and it would be pretty simple. However you can just use Java EE mechanisms for that.

Arjan Tijms
  • 37,782
  • 12
  • 108
  • 140
Pavel Horal
  • 17,782
  • 3
  • 65
  • 89
  • 1
    So, you mean maintaining one instance per session, persisting inside session are 2 examples of how a stateful bean can provide for us?? HttpSession can also maintain one instance per session, but I'm not so sure about "persisting inside session". Anyway, can you make a list of things that we have to do if we use a "HttpSession + a normal Java class" instead of using a stateful session bean?? – echipbk Oct 06 '13 at 12:31