• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting "HttpSession" object

 
Dima Riabin
Greenhorn
Posts: 18
MyEclipse IDE Windows Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 122
IntelliJ IDE Java Mac
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 79
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18
MyEclipse IDE Windows Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic