Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

storing values in session

 
Rajaprabhu Aravindasamy
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 290
Debian Fedora Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you guys..
I'll try this and post the result soon..!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic