• Post Reply Bookmark Topic Watch Topic
  • New Topic

Retriving value from session in JSF

 
Priya Joshi
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

In my application i want to save username at the time of login in session. I have written that code as follows:

HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
request.getSession().setAttribute("uname", name);

I want to retrive this uname variable in other page.
How i can do this?
can anyone help me?

Thanks in advance..
 
Himanshu Gupta
Ranch Hand
Posts: 598
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You may make use of this code.
 
Himanshu Gupta
Ranch Hand
Posts: 598
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To use the above code you have to make use of map.
 
Priya Joshi
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks himanshu
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To set it, obviously use sessionMap.put("user", user).

Better design is to just store it in a session scoped managed bean. Managed beans can access each other by the managed property injection, or by the sessionMap.
[ September 26, 2008: Message edited by: Bauke Scholtz ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!