0

I have a web application using spring/hibernate. i have a requirement. i am keeping some info in session. Before the session gets timed out, i need to take back up of all the session objects and again i need to put the session objects back into the session once new session gets created. Once the session is timed out, user wil be shown the login page and once the user is logged in, i need to get the stored session information of the logged in user from the back up and keep in the session.

Two achieve above things i need to implement HttpSessionListener. In one stretch how can i take the back up of all the session objects of all the users logged in. Once new session gets created then again i neeed to take the session objects of logged in user from the back up and keep in the session. Please suggest me the approaches.

public class MySessionListener implements HttpSessionListener {

   @Override
    public void sessionCreated(HttpSessionEvent event) {
    }

    @Override
    public void sessionDestroyed(HttpSessionEvent event) {
    }
}
user755806
  • 6,565
  • 27
  • 106
  • 153

2 Answers2

0

I think you should store your data into database instead of such way. it's is not good approach to maintain data such way. I am not aware about your application requirement. but right approach to set data when session set & remove attribute after session expired.

It will create security thread if your application concern with security. Do good coding with right approach and pattern instead of to achieve small thing with very fast result.

bNd
  • 7,512
  • 7
  • 39
  • 72
0

The Servlet API won't provide you a way to list all valid session objects. You have to get a hold on them. Being the creator, it should not be difficult to know this.

For taking backup, Database seems to be the perfect one. You can write to DB in sessionDestroyed method for that particular User. And in sessionCreated method, you can retrieve values for that User from DB.

References : how do i get a list of all httpsession objects in a web-application

Community
  • 1
  • 1
Vikas V
  • 3,176
  • 2
  • 37
  • 60