File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Getting Session in Struts2" Watch "Getting Session in Struts2" New topic
Author

Getting Session in Struts2

Vishal Sinha
Greenhorn

Joined: Jul 17, 2008
Posts: 6
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

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
Greenhorn

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.

Regards...
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8927
    
    9

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


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Meiyappan Kannappa
Greenhorn

Joined: Sep 15, 2008
Posts: 10
http://intricatetips.blogspot.com


Warm Regards
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Getting Session in Struts2