• 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

Display message after session timeout in struts2

 
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How to display a message after the session times out after 30 mins.
 
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
Depends on what you mean by that.

HTTP is a stateless protocol. Unless the client makes a request there's no way for the browser to know the session has expired.

You *could* fire off an Ajax request every minute or something, from every page, and if the session has expired, redirect to a new page. Otherwise you'd just check for a valid session on every request (like from a filter or interceptor) and redirect if it's expired.
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dave,
Wouldn't the session not expire if you are pinging it every minute? Or are you proposing tracking inactivity (the pings don't count) and expiring via code after 30 minutes.
 
David Newton
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
Oh, hmm. I've run circles 'round myself logically.

I guess you could track access against all but the "am I alive?" XHR request, setting a session last accessed object (separate from the session's actual time) and checking it in the XHR request handler (but not updating it) or something.

Hrm. That's funny.
 
Hrishikesh Maluskar
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have used this web.xml


The session gets expired after 30 mins, i want to display a message after this.
 
David Newton
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
As explained, the client has no way to know when the server session expires without asking it (the server).
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I came across this in my search for an answer to the same question. What i think is...

  • Create a javascript variable that will hold the session timeout value (sent from the server)
  • Create a javascript interval that decrements this value (say, every second?) e.g.


  • Every time the page reloads, or an xhr request returns, reset the sessionLife variable to SESSION_TIMEOUT
  • Whenever the sessionLife variable gets to zero, alert the user with javascript that his session is expired; then he clicks a button that takes him back to the login page.
  •  
    reply
      Bookmark Topic Watch Topic
    • New Topic