aspose file tools*
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
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Getting "HttpSession" object