wood burning stoves 2.0*
The moose likes EJB and other Java EE Technologies and the fly likes Session Bean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Session Bean" Watch "Session Bean" New topic
Author

Session Bean

Poornima Sharma
Ranch Hand

Joined: Sep 09, 2008
Posts: 114
Hi Friends,

I am a novice in EJB. I have problem in understanding the word state in Stateless/Stateful session bean in context to servlets i.e, web applications. Is the stateful session bean similar to a HttpSession? Can they be used alternatively?


Poornima Sharma
SCJP 6.0
amit punekar
Ranch Hand

Joined: May 14, 2004
Posts: 514
Hello,
HTTPSession represents the user session accessing your application.
Stateful session bean maintains the state of the client in between different service/method invocation on that bean.
Generally you put the handle of the Stateful session bean in the HttpSession. This handle can be retrieved from the HttpSession.getAttribute() and then SFSB method can be invoked on the same.

Stateless Session beans - They are not supposed to maintain the client state between method invocation. The instance of the SLSB being used to serve the client's request is transparent to the client.

Regards,
amit
Poornima Sharma
Ranch Hand

Joined: Sep 09, 2008
Posts: 114
Hi Amit,

You mean that once we have injected a stateful session bean in a web application, we should keep that SFSB object in HttpSession and use it wherever needed, just like other bean objects. Is this the process to maintain state of the bean?

Thanks,
amit punekar
Ranch Hand

Joined: May 14, 2004
Posts: 514
hello,
I am not sure about Injection.
I mentioned the approach earlier where we had done the lookup of SFSB and then store the handle of it in HttpSession.
State of the bean will be maintained by the container and not you. You only map the instance of the SFSB to the User (logged in probably) using the HttpSession.

Hope this helps, though you need to wait for some answer on the injection aspect of your question.

regards,
amit
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Session Bean