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 HttpSession and 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 "HttpSession and Session Bean" Watch "HttpSession and Session Bean" New topic

HttpSession and Session Bean

Kalpana Balasubramanian

Joined: Dec 22, 2005
Posts: 8
Can anyone please clarify me this question.
Whether the userstate maintained in HttpSession can be made avaiable in EJB Stateful/Stateless session bean?
Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

Well, the EJB doesn't have direct access to the HttpSession but you can pass the session to the EJB as a parameter (assuming everything in it is Serializable). Not a good thing to do though, since it ties your EJB method to a web client and any cahnges your EJB method makes to the HttpSession will not be reflected in the actual HttpSession itself.
[ March 19, 2007: Message edited by: Paul Sturrock ]

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Mark Spritzler

Joined: Feb 05, 2001
Posts: 17276

So in that case, you would have to get the stuff out of the HttpSession, put it into some other class that you create, pass that to the EJB, do stuff, and put the changes into that new class, return that, then take it out of that object, and put it into the HttpSession.


Perfect World Programming, LLC - iOS Apps
How to Ask Questions the Smart Way FAQ
Kalpana Balasubramanian

Joined: Dec 22, 2005
Posts: 8
Thanks for the help.

I did that way only, I created a User class which is passed back and forth with the updated information. It is working fine.

Thanks again!
I agree. Here's the link:
subject: HttpSession and Session Bean
It's not a secret anymore!