This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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?
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.
Joined: Sep 09, 2008
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?
Joined: May 14, 2004
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.