aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes How to get SessionContext ??? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "How to get SessionContext ???" Watch "How to get SessionContext ???" New topic
Author

How to get SessionContext ???

Frank Jacobsen
Ranch Hand

Joined: May 17, 2002
Posts: 356
I have a stateless session bean:

public class AdminSesssionBeanBean implements javax.ejb.SessionBean {
private javax.ejb.SessionContext mySessionCtx;

The bean is running, but i have a other class in the session bean where i need to get the SessionContext, how do i get the sessioncontext ???

SessionContext ctx = ???

Frank
Valentin Tanase
Ranch Hand

Joined: Feb 17, 2005
Posts: 704
Hi Frank,

What do you mean by "i have a other class in the session bean"? Do you have an inner class or another class within the same java file? You can solve your problem in two ways: one way is to pass the session context to the class� constructor, if it is instantiated inside of the session bean. Otherwise you can always define a business method like SessionContext getSessionContext() and have your private class calling it using normal jndi lookup, findByPrimaryKey(), etc. Because I doubt that session context object is serializable you can define this method only on the local interface. However you should ask yourself the obvious question how much sense does it make, from a designing perspective to define a business method that returns the session context? It would at least be acceptable if you could define an ejbHomeGetSessionContext() on the home interface, but this I guess is impossible since you need to return a reference to the current instance�s context.
Regards.


I think, therefore I exist -- Rene Descartes
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to get SessionContext ???