• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Display message after session timeout in struts2

 
Hrishikesh Maluskar
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to display a message after the session times out after 30 mins.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • 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.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34656
366
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • 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
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • 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
  • 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
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As explained, the client has no way to know when the server session expires without asking it (the server).
 
Ikenna Okonkwo
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • 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.
  •  
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic