• Post Reply Bookmark Topic Watch Topic
  • New Topic

Jsp and EJB session

 
Claudia Vaz
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello
In a Jsp application i can access session EJB.
I have two questions:
1. I instantiate a EJB session in a Jsp. When i do a submit or forward to another page, do the EJB session stills remains?
2. If i have a class in the EJB session with variables (like a JavaBean class), does the values of those variables are lost?

Thanks in advance
Hope someone can help!
Claudia Vaz
 
Dave Landers
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It sounds like you are talking about a Stateful Session Bean (not Stateless).
In that case, you want to put the handle to the bean in the HTTP Session. Then you can retrieve it on some other page and keep working with it.
The Stateful Session Bean and all it's data (state) remains until it is removed (by calling the bean's remove() method) or it times out (setting the session timeout is a server-specific thing).
See section 6.8 (page 65) of the EJB 2.0 spec for an example. Oh heck, nobody reads the specs anymore - here it is briefly:

A client creates a remote Cart session object (which provides a shopping service) using a create< METHOD>(...) method of the Cart s remote home interface. The client then uses this session object to fill the cart with items and to purchase its contents.
<snip>
For the following example, we start by looking up the Cart s remote home interface in JNDI. We then use the remote home interface to create a Cart session object and add a few items to it

Next we decide to complete this shopping session at a later time so we serialize a handle to this cart session object and store it in a file:

Finally we deserialize the handle at a later time, re-create the reference to the cart session object, and purchase the contents of the shopping cart:


You'd stick it in the Http Session rather than doing the "serialize to file" thing.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!