Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting Session in Struts2

 
Vishal Sinha
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey,
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
Posts: 2187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Regards...
 
Joe Ess
Bartender
Pie
Posts: 9265
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Struts 2 FAQ: How do we get access to the session
 
Meiyappan Kannappa
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
http://intricatetips.blogspot.com
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic