This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Struts and the fly likes storing values in session 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 "storing values in session" Watch "storing values in session" New topic
Author

storing values in session

Rajaprabhu Aravindasamy
Greenhorn

Joined: Dec 26, 2011
Posts: 25
Hello guys..
I'm a newbie to Struts2.and now i'm creating a small application by using it.
In this, i want to add username into session whenever i do login. and whenever i click logout link i need to destroy the username in session.
so that i will check whether the session is containing username or not and after that i will provide authorization to view the pages.
My question is ..
how to set username in session ?
how to access it in jsp page..?
and how to remove it .?
please explain it with corresponding syntax...
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Rajaprabhu Aravindasamy wrote:
how to set username in session ?

1. create a new session upon successful authentication

2.and set user name;redirect to welcome page

*dont use jsp for this purpose
Rajaprabhu Aravindasamy wrote:
how to access it in jsp page..?

Use Expression Language
${sessionScope['userName']}
Rajaprabhu Aravindasamy wrote:
and how to remove it .?

invalidate existing session


or for removing particular attribute-userName


*dont use jsp for this purpose

Arun Giridharan
Ranch Hand

Joined: Sep 30, 2010
Posts: 290

to access session , implement SessionAware Interface in Your Action Class. In jsp use session or attr to access.
<s:property value="#attr.username"/>.
Rajaprabhu Aravindasamy
Greenhorn

Joined: Dec 26, 2011
Posts: 25
Thank you guys..
I'll try this and post the result soon..!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: storing values in session
 
Similar Threads
Windows username
how to get the username from the session
how to use the servlet to get the value from JSTL c:set?
Query regarding Session Tracking
Passing parameters to different view