Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HttpSession object VS StatefulSession Bean

 
Tina Desai
Ranch Hand
Posts: 365
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Friends,

The following question keeps popping up in discussions and
I need some help on this.

"We can maintain the session using the HttpSession object, then why
do we need stateful session beans?"

Thank you in advance!

Regards,
Tina
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An enterprise EJB application must be designed to support various types of client, eg web, Swing, web service, EJB. For such an app, I would say that conversational state should usually be maintained in the business logic layer using stateful session beans. (Another alternative is to store state in the DB, which is secure but slow.) And if you store state in the web tier, this will result in duplicate data storage for the web clients.
 
Sravan Kumar
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For one reason, if you want to use the bean services through some other means, say WAP, you need stateful-ness of the beans.

From a professional/business point of view, the web layer and the business layer should be decoupled as loose as possible in design. Beans are business objects and such an object, where necessary, should maintain state. When we design the work flow, we design to requirements and not to technology.

It is upto us to strike a deal, judiciously, of course, whether we can maintain state using HTTPSession or EJB's, though both give us options.
 
Tina Desai
Ranch Hand
Posts: 365
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you to both of you Roger and Coffee. Very to the point and clear replies. I got it now.

Coffee, sorry if this feels a little ungrateful at this moment. We have a Naming Convention on Javaranch. You may want to take a look at the link

Regards,
Tina
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic