This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Struts2 and accessing session object from JSP?

 
André-John Mas
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 689
Eclipse IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic