• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Targetting specific Objects in session

 
Ranch Hand
Posts: 430
Android VI Editor Debian
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have a java bean that i store in each user's session. Each jsp page contains the following line..



The User object contains information about the user and a list IDs of products they can view.

I have a Servlet which add and removes these lists of products from users. The problem i have is if a user's account is updated, i would like this user's bean to be refreshed.

I cant think of an easier way to do this. How do i access each User object for each user in all sessions so that i can invalidate the ones i want?
[ May 23, 2006: Message edited by: O. Ziggy ]
 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't really understand the problem here.

The JSPs will always get the current data from the User object in the session. It doesn't cache this data. What do you mean, when you say you want to refresh User object.

Is your servlet(which updates the User object) not being called every time the user data is updated?

The problem i have is if a user's account is updated, i would like this user's bean to be refreshed.


Any object is session is latest one. What do you mean by refreshing?

How do i access each User object for each user in all sessions so that i can invalidate the ones i want?


If you want to share data across sessions, you either need to put it in ServletContext or you have to put it in some external resource like database.
 
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm assuming the servlet is run by a different Session than the logged in user. Something like an Admin Servlet right?

If so, there are several ways to handle this.

1) have the user refresh from your data store on each request

2) create an HttpSessionBindingListener and place it in the ServletContext as each User is created, get the sessionId and place it in a map. The servlet can then get the map and refresh the user. If a user is unbound, remove it from the map.
 
O. Ziggy
Ranch Hand
Posts: 430
Android VI Editor Debian
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Basicly when the user logs on, his or her details are stored in the "User" bean. This details come from the database and stored in this bean which is available to the user for the scope of the session.

Every request the user makes uses this bean to check what products the user can view. This bean is created when the user logs in. The only way to refresh it is to log out the user.

If this user's profile is updated, the change is made to the database. If the user is still logged on, the bean in his session will still contain the old profile information.

I am trying to refresh or destroy all User beans on all sessions if a user 's profile is updated. This will force the beans to be re-created with the updated information.

Hope that made it clearer.
[ May 24, 2006: Message edited by: O. Ziggy ]
 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Pusing invalidation message to all session variables would be difficult to achieve, but you can have some kind of check in your user bean which checks for last update date in your web application either the database or some variable in application wide context.

- Ravindra
 
O. Ziggy
Ranch Hand
Posts: 430
Android VI Editor Debian
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got it to work.

Basicly each "User" bean object has a field for the time it is created. Whenever a user profile is updated i use a global date which is set to the time the update took place.

Everytime any user makes a request i compare the time their bean was created with the time the the last update took place. If the bean was created before the update then the session is invalidated.

Cheers..
reply
    Bookmark Topic Watch Topic
  • New Topic