wood burning stoves*
The moose likes JSP and the fly likes Capture Session Timeout and Forward to JSP page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Capture Session Timeout and Forward to JSP page" Watch "Capture Session Timeout and Forward to JSP page" New topic
Author

Capture Session Timeout and Forward to JSP page

jarrett grantham
Greenhorn

Joined: Apr 25, 2003
Posts: 2
I am attempting to capture the session timeout and forward to some jsp page when timeout occurs. I am using Weblogic 6.1; can someone point me in the right direction on how to do this?
Thanks, Jarrett
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
You need to do a session check before anything else for every request. This could be done, for example, with a filter (see javax.servlet.Filter) or by having each servlet to inherit from some kind of "SessionValidatorServlet", which redirects requests without a session to the login page.


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Matthew Phillips
Ranch Hand

Joined: Mar 09, 2001
Posts: 2676
You can implement the HttpSessionListener interface. The sessionDestroyed method is called when the session is invalidated.


Matthew Phillips
Matthew Phillips
Ranch Hand

Joined: Mar 09, 2001
Posts: 2676
Originally posted by Matthew Phillips:
Your filter can implement the HttpSessionListener interface. The sessionDestroyed method is called when the session is invalidated.
jarrett grantham
Greenhorn

Joined: Apr 25, 2003
Posts: 2
Sorry, I wasn't specific enough. I am using struts and I would like to automatically forward to some notification page when the session expires; but I want this to happen without user intervention. For example, a user leaves a browser unattended for 30 min & session timeout is 30 min; I would want the page to automatically forward to another page without the user submitting the page.
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
How about putting a refresh interval into the HTML HEAD section of the page to "poll" session timeout?
Carlos Vassallo
Greenhorn

Joined: Apr 03, 2003
Posts: 6
hi, I think that your timer might be on the client. JSP couldn`t do so much in that case.
I little bit ago, I really need to use that but my application runs over an intranet and all the browsers are IE, so the problem reduces to use this VB Script
'Object to hold the timer
Dim idTimer
'time of life of the session
Dim sessionTimeOut
function startTimer(vTime)
if time <> "" then
sessionTimeOut=vTime
else
vTime=sessionTimeOut
end if
idTimer = setTimeout ("goOut()", vTime)
end function
function goOut()
location.href="miUrl"
end function
function resetTimeOut()
clearTimer idTimer
startTimer ""
end function
I hope that this help.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60053
    
  65

How about putting a refresh interval into the HTML HEAD section of the page to "poll" session timeout?

Since each "poll" will reset the session timeout, this will simply cause the session to never time out.
bear


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Originally posted by Bear Bibeault:
Since each "poll" will reset the session timeout, this will simply cause the session to never time out.

Naturally this approach would require using some timestamp object within the HttpSession. A lot of work, ugly implementation, and a non-recommended solution in many other ways. Agreed.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Capture Session Timeout and Forward to JSP page
 
Similar Threads
Capturing Session TimeOut?
How to invaliddate session when browser Window is closed using [x] button
session invalidate
Session Timeout in Struts1.3
session timeout