Win a copy of OCP Oracle Certified Professional Java SE 11 Developer Practice Tests this week in the OCP forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Ron McLeod
  • Tim Cooke
Sheriffs:
  • Devaka Cooray
  • paul wheaton
  • Mark Herschberg
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Frits Walraven
  • Jj Roberts
Bartenders:
  • Carey Brown
  • salvin francis
  • Piet Souris

Session Time out

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How to show an alert message when session time out, during application execution? Please let me know.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This application is web application or stand alone java application
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You'd have to poll the server (probably via Ajax and timer event) to find out--the server can't push this information to the client.
 
Ranch Hand
Posts: 544
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
If we hit the server using Ajax then would not it keep the session alive on server?
Please correct me if I understood this wrong.

Regards,
Amit
 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In that case you cant use session time out method [setMaxInactivInterval].

1. Poll an AJAX request and manually calulate the timeout period

if(CurrentTime - HtpSession.getCreationTime - timeOut) = TIMEOUT - [alter_period]) {
sendalert response to rest timeout.
}else if(CurrentTime - HtpSession.getCreationTime - timeOut) = TIMEOUT){
invalidate
}

2. write another filter resetTimeOut

if(request = isNot[AJAX timeout request]
- reset timeout variable


This is the best i got.
 
Ranch Hand
Posts: 580
Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am not sure if i have the answer but ...
when the session has timed out then the class that is implementing HttpSessionListener interface can do something.... given that you want to do something AFTER the session has timed out
 
Sheriff
Posts: 67497
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But one thing such a listener cannot do is to communicate with the client in any way. To issue an alert, for example.

The OP is thinking of the problem backwards. Upon a request, whether the session has expired of not can be checked (a filter is great for this). But if no request has been made, there's not much to be done.
 
Listen. That's my theme music. That's how I know I'm a super hero. That, and this tiny ad told me:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic