Help coderanch get a
new server
by contributing to the fundraiser
  • 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

Allowing a Session to stay alive when browser closes

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is there any way to create a session and have it stay alive on the user side when the user closes and then re-opens the browser? I can do it if I create my own cookie and use cookie.setMaxAge(5*60*60); I understand the cookie in the user's browser will be there for five hours even if the browser is closed and reopened. But I would like to use Session objects. I don't see how to keep a session alive if the user closes his browser. I think I understand the server side of Sessions in that if I use session.setMaxInactiveInterval(5*60*60) I know the server side session object will be alive for 5 hours even with no activity from the user. But if the user closes his browser, tough luck, the server side session object is still there, but the re-opened browser has no cookie so the container will create a new session and I am wasting memory with the old session. Should I just trample off and use cookies?
Thanks for any help.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, once the user closes the browser, that's it. They're disconnected from that session and won't be able to re-connect to it.
 
edwardo deleon
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks. Now I have something to do tonight, tomorrow and over the weekend. Cookies here I come!
 
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there...
while in this topic, using the seMaxAge() method, how can I make my cookie live at the client machine forever until physically removed by the client?
in other words, what is the value that should be passed to setMaxAge() method?
Thank you in advance
Hatim
 
Ranch Hand
Posts: 1514
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You just have to set the maxage to a very high value.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Bosun Bello:
You just have to set the maxage to a very high value.



Bosun,
The original poster was asking about reconnecting to an existing session after the browser has been closed. A longer session timeout will not help in this case.
 
Ranch Hand
Posts: 1162
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Bosun Bello:
You just have to set the maxage to a very high value.



or just use -1 to set it to infinity.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Chunnard Singh:


or just use -1 to set it to infinity.



Again,
This is irrelevant once the browser has been closed.
 
Live a little! The night is young! And we have umbrellas in our drinks! This umbrella has a tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic