• Post Reply Bookmark Topic Watch Topic
  • New Topic

Restoring a session variable after timeout  RSS feed

 
Luke Zechariah
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hello, my application uses Struts and IBM Web application Server. I have a question regarding session management. I have a variable stored in session scope, i.e. the name of the client. it is a intranet application. Now whenever the user leaves the browser screen for a long time, the session times out and losses the name of the client.

Could anyone suggest a way of how to restore the variable after the client comes back and starts using the browser and refreshes the screen and starts using the application. I want just the browser to remember the session variable i.e. "name" of the client.


Thank you,
Arun.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cookies perhaps?
 
Luke Zechariah
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes I thought about cookies but is there anything else?

 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In modern browsers, there's local storage. But you cannot rely on it if you need to sport legacy browsers.
 
Luke Zechariah
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Should we save it to a file on the computer of the client when the session is invalidating? Is that a good suggestion. When a new session is later opened the file text is read for the "name"?

Thank you.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What advantage would that have over a cookie solution?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another question: if you don't want the session info to expire, why not just change the session timeout limit?
 
Abhay Agarwal
Ranch Hand
Posts: 1376
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
write session info in database can be the option before data is moved out of session due to timeout.
Same info can be retrieved from DB table again when session is restored.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How would the database be queried? How would the correct db record be selected?

I'm still not understanding why a cookie isn't the obvious approach.
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Usually, I get the client identity from the user ID (getRemoteUser). I can then use it to locate information relating to the session that's been placed in persistent storage.

A cookie can be used, but that only works in cases where the same user is attempting to reconnect from the same computer using the same browser.
 
osagie uwaifo
Greenhorn
Posts: 2
Java Linux Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Another question: if you don't want the session info to expire, why not just change the session timeout limit?


I would also second the solution Bear suggested. You could also notify the user that there session is about to expire and have them "re-login". You can try the solution here
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!