wood burning stoves 2.0*
The moose likes Struts and the fly likes Struts2 and accessing session object from JSP? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts2 and accessing session object from JSP?" Watch "Struts2 and accessing session object from JSP?" New topic
Author

Struts2 and accessing session object from JSP?

André-John Mas
Ranch Hand

Joined: Oct 18, 2008
Posts: 37
I have added an object to the session map from within my ActionSupport class. I would like to know display it in my page. I am doing something of sorts:

ActionSupport class (implements SessionAware):

sessionMap.put("user",userInstance);

JSP:

<s roperty value="#session.user.firstName"/>

Though non of this seems to work. Any help would be appreciated.
André-John Mas
Ranch Hand

Joined: Oct 18, 2008
Posts: 37
Further investigation shows that indicating my class as implementing SessionAware is not sufficient, since the map never contains the value next time the action is called. What am I missing?
Nishan Patel
Ranch Hand

Joined: Sep 07, 2008
Posts: 684

Hi...

Why you use Map for user session.

It is better to use direct like.

HttpSession session = request.getSession (true);

session.setAttribute ("user", userList.get(0));

and then you can access it

<s roperty value="#session.user.firstName"/>

Thanks,
Nishan Patel


Thanks, Nishan Patel
SCJP 1.5, SCWCD 1.5, OCPJWSD Java Developer,My Blog
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Struts2 and accessing session object from JSP?
 
Similar Threads
how to do "redirect-action" to some action from within ActionSupport?
s:text issue Struts 2
Struts 2: Action objects not passed to JSP
Form Data not being populated in Struts 2
How to iterate my vector...?