| Author |
a question about Stateful Session Beans...
|
Andres Gonzalez
Ranch Hand
Joined: Nov 27, 2001
Posts: 1561
|
|
I have created a shopping cart component (stateful session bean), but I'm confused with the concept, i guess.. When you work with HttpSession you can access the session object doing something like: and you can access the session in any servlet, for instance, just by invoking the request.getSession.. Now, when I initialize my Session Bean, I do something like: once I do this, i can invoke any method of my bean (add items, remove items, etc..). so far so good... but, if I get another request to a different servlet from the same client, for example, how do I get the reference to this session bean? if I do home.create i will be creating another instance , right? hope you guys understand... thanks
|
I'm not going to be a Rock Star. I'm going to be a LEGEND! --Freddie Mercury
|
 |
william kane
Ranch Hand
Joined: Nov 21, 2000
Posts: 260
|
|
|
When you are in a different Servlet and you invoke create you get a diffent session bean coz the server considers you as a different client.If you want to access the same session bean you can place the session bean in the Http session object and get it back in the subsequent servlet using the get method.I am not sure though of the performance bottle necks this approach might induce.
|
Help me!Help you!!!
|
 |
Andres Gonzalez
Ranch Hand
Joined: Nov 27, 2001
Posts: 1561
|
|
Originally posted by william kane: When you are in a different Servlet and you invoke create you get a diffent session bean coz the server considers you as a different client.If you want to access the same session bean you can place the session bean in the Http session object and get it back in the subsequent servlet using the get method.I am not sure though of the performance bottle necks this approach might induce.
thank you.. that's the approach I was following. So what's the point of having the session bean if you are going to use the HttpSession object anyway. So you create the session bean and put it in the session variable... now I'm confused.. I thought you can use either HttpRequest or Stateful Session Beans
|
 |
william kane
Ranch Hand
Joined: Nov 21, 2000
Posts: 260
|
|
Originally posted by Andres Gonzalez: thank you.. that's the approach I was following. So what's the point of having the session bean if you are going to use the HttpSession object anyway. So you create the session bean and put it in the session variable... now I'm confused.. I thought you can use either HttpRequest or Stateful Session Beans
Hi Andres, The http client for your application is NOT your bean client rather its your servlets in you web app that are clients for your EJBs.Therefore your HTTPSession needs to map to your EJB. I still,cannot understand your query :-(
|
 |
Andres Gonzalez
Ranch Hand
Joined: Nov 27, 2001
Posts: 1561
|
|
Thanks william... I understand your point.. I also did some more research and found this articles... http://www.onjava.com/pub/a/onjava/2001/10/02/ejb.html http://www.theserverside.com/discussion/thread.jsp?thread_id=552 <extracted-from-article> If your application server does not support HttpSession cache management -- and you need to control the total number of session-oriented instances in memory at any given time -- you should place the bulk of your session-oriented data in an SFSB instead of an HttpSession object. You will still need to maintain an HttpSession for each client, but the only item in the HttpSession should be a reference to the SFSB for that client. If the only item in the HttpSession object is a reference to the SFSB, the amount of memory consumed by each HttpSession object is minimal and cache management of these instances is not needed. The bulk of memory consumption will occur within the SFSBs, which have a standardized strategy for allowing a container to perform cache management. For systems that do not have a servlet/JSP front-end, SFSBs should be used to track session-oriented state similar to the way a web-based system would use an HttpSession object. This was the primary intent of SFSBs when they were created. </extracted-from-article> My system will only have web clients.. So does this mean that I could've used only HttpSession instead of stateful session beans? thanks again
|
 |
 |
|
|
subject: a question about Stateful Session Beans...
|
|
|