File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes EJB and other Java EE Technologies and the fly likes Question on Statefull Session Bean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Question on Statefull Session Bean" Watch "Question on Statefull Session Bean" New topic

Question on Statefull Session Bean


Joined: Aug 27, 2002
Posts: 11
If one is using a statefull session bean, how does one get a handle to it from one JSP page to the other JSP page.
Valentin Tanase
Ranch Hand

Joined: Feb 17, 2005
Posts: 704
First of all you might be aware that this is not a good practice with SFSB. This especially because SFSBs suppose to be single threaded and in case of receiving two concurrent requests from two different clients, your container might throw an exception. The second observation it�s a common problem with ejb handles: if the container passivates/removes the bean instance, then your handle is useless.
Having said that, you have two choices: either to add the handle to the session or to serialize the handle to a common directory. For the first case you still have to worry about the case when your server fails and the session needs to be recovered. In this case you might recover your handle or you might not. The second scenario will save the handle in all circumstances. You need your first JSP to serialize the handle like this:

While the second JSP will get the handle from the common folder:


I think, therefore I exist -- Rene Descartes
Ranch Hand

Joined: Dec 05, 2004
Posts: 48
As Valentin explained, It is not a good practice to share the handle of SFSB. Further, Serializing the handle in a common subfolder is again a risk.
In most corporate applications, load balancing is very common and folder can not be shared. So keeping in that mind, think about better viable solution to your need.

Thanks,<br />Bhanu<br />SCEA Step-I<br />SCBCD for J2EE 1.3<br />SCJP1.4
I agree. Here's the link:
subject: Question on Statefull Session Bean
It's not a secret anymore!