• Post Reply Bookmark Topic Watch Topic
  • New Topic

How can a bean to get a object in application scope  RSS feed

 
guo mark
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got a object of Bean that hold the infomation of the current user in the session scope.
How can i get the reference to the object?
I write code below,but it does't works:
user = (CertUser)getServletContext().getAttribute("cert");
 
Rene Larsen
Ranch Hand
Posts: 1179
Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this:

Rene
 
Sarath Mohan
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes this is a viable solution. But bean is dependent to the sevelet environment. I mean this bean can't be utilised in an application.
This may be a better approach
Use the above code:
Userinfo userInfo = (Userinfo) request.getSession().getAttribute("UserInfo");
in either JSP or Servlet itself and using setter/getter method in Bean to get and get the same object.
 
guo mark
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
3x.I have got the solution
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!