wood burning stoves 2.0*
The moose likes Struts and the fly likes Display message after session timeout in struts2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Display message after session timeout in struts2" Watch "Display message after session timeout in struts2" New topic
Author

Display message after session timeout in struts2

Hrishikesh Maluskar
Ranch Hand

Joined: Jun 19, 2008
Posts: 115
How to display a message after the session times out after 30 mins.


SCJP 1.5
www.licexpadvice.com
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

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

Joined: May 26, 2003
Posts: 30789
    
157

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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Jun 19, 2008
Posts: 115
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

Joined: Sep 29, 2008
Posts: 12617

As explained, the client has no way to know when the server session expires without asking it (the server).
Ikenna Okonkwo
Greenhorn

Joined: Nov 18, 2010
Posts: 2
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.
  •  
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Display message after session timeout in struts2