This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Struts and the fly likes Getting Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Getting "HttpSession" object" Watch "Getting "HttpSession" object" New topic
Author

Getting "HttpSession" object

Dima Riabin
Greenhorn

Joined: Jan 05, 2011
Posts: 16

Hi.
I am porting the existing project written in JSP and cor Java (no framework used) to the use of Struts 2
The way it's written now, is that JSP use a lot of scriplets calling custom Java classes, and overal creating the mess.

I sort of successfully ported navigation to using Action classes, and now came to interesting problem, that I do not know how to resolve.

There is a mechanism written with some Helper Class, that works fine, and it's very big so I don't have to change it. I have to call the methods of this Helper class from my action classes now.
Due to poor design previously, many of the methods use "HttpSession" object in a signature. Something like

.. void load(HttpSession s, s.. ...) {
}

Now, from my action class, I want to do
Helper.load..(mysession, ..)...

The mysession is of type HttpSession.
I know how to use ActionAware interface, with getSession .. or ParameterAware interface with getParameter.. However,I have my session object available to me as a Map, and not as a HttpSession object. I can't figure out how to get the actual HttpSession object in Struts2 ... ActionContext.getContext() .. doesn't seem to give me any access to it

Can anyone help ?
Jesus Mireles
Ranch Hand

Joined: Mar 10, 2010
Posts: 122

I've never needed to do this but I remember when I was learning about SessionAware I think I recall you can do:

ServletActionContext.getRequest().getSession()

Which will get you an HttpSession
khekhone yvan
Ranch Hand

Joined: May 08, 2011
Posts: 79
Map session = ActionContext.getContext().getSession();
session.get("SessionId");
before that you have to store on the ssessioon like this
Map session = ActionContext.getContext().getSession();
session.put("SessionId",temp.getID_personne());
Dima Riabin
Greenhorn

Joined: Jan 05, 2011
Posts: 16

[quote=Jesus Mireles]ServletActionContext.getRequest().getSession()

Which will get you an HttpSession
[/quote]

Yes, thanks. This is what I did. I found it by browsing through Struts related class libraries for class names with the "Servlet" in them, and found this mechanism.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Getting "HttpSession" object
 
Similar Threads
Using the Strategy Pattern in Struts Actions
where to turn next? need help with model layer talking to the database
How to access session variable in the jsf page
[URLyBirdHotel 1.3.3] Can I add more interfaces on Data.java?
Action Class or Regular Java Class to use?