Meaningless Drivel is fun!
The moose likes Struts and the fly likes Getting Session in Struts2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Getting Session in Struts2" Watch "Getting Session in Struts2" New topic

Getting Session in Struts2

Vishal Sinha

Joined: Jul 17, 2008
Posts: 6
I am really breaking my head to get session object in my action class.
When I login to a certain portal, the portal sets the user name to the session object. Now on the portal user clicks on my application which is written in struts2. When I get the session map using sessionaware interface, I get an empty map.
I also tried using ServeletrequestAware interfacae to get httprequest and called getSession() on it. Still I am getting empty session.

Can someone tell me how can I get the session which contains username set by the portal? Do I need to change something in struts-config.xml?
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
The portal application sets a value in the HttpSession object. There is a link to another application. When you click on a link, it takes you to the other application. The session object created in the portal application may not be accessible from a separate application. As far as I know, the HttpSession object is only alive for a particular session with a particular application. Once you leave the application to go to another, the session object does not follow you.
Vishal Sinha

Joined: Jul 17, 2008
Posts: 6
Hi James,
Actually my application is a part of portal and runs in the same JVM. Earlier without using struts2 (when it was plain JSP)I was able to get the session object. So may be I am not getting the session object correctly or may be Struts2 is creating a new session object. What is the correct way of accessing the session object with all its attributes. Please let me know the changes in struts-config also.

Joe Ess

Joined: Oct 29, 2001
Posts: 9189

Struts 2 FAQ: How do we get access to the session

[How To Ask Questions On JavaRanch]
Meiyappan Kannappa

Joined: Sep 15, 2008
Posts: 10

Warm Regards
I agree. Here's the link:
subject: Getting Session in Struts2
It's not a secret anymore!