Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • salvin francis
  • fred rosenberger

Jsp and EJB session

Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
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.
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.
Cob is sand, clay and sometimes straw. This tiny ad is made of cob:
Devious Experiments for a Truly Passive Greenhouse!
    Bookmark Topic Watch Topic
  • New Topic