tags:

views:

19

answers:

1

Dear members,

How to get the session object of an EJB session-bean like session object in JSP(web layer)?

Because I want to add an attribute to the session and use it later in its process.

Regards

+1  A: 

In the web layer you get the session with

request.getSession()

This returns the session object tied to this request. Here you can store session specific attributes you can reuse on subsequent requests.

In the EJB layes you have completely different session objects which have nothing to do with the session above. There are Stateless Session Beans and Stateful Session Beans. Stateful session beans can also keep state over multiple requests however they are very tricky to work with and are only useful for a very limited set of use-cases. Stateless Session Beans do not keep (outside detectable) state between calls, so are useless to store attribtes you want to reuse later, unless you store them in a persistence layer or a cache.

In most cases the easiest to work is to keep the conversation state in the request session object and pass the attribute you want to reuse later from the web layer to a stateless service bean as a parameter.

Peter Tillemans