• Post Reply Bookmark Topic Watch Topic
  • New Topic

session timeout using javascript  RSS feed

 
p kiran
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am using JSF, I want to logout a user once the user session timeout happens. I did add the following tag;
session-config
session-timeout 5 session-timeout
session-config
and implemented the HttpSessionListener.

My session gets timedout but it will not indicate anything on my JSP.
For this I add a JAVASCRIPT code which calls the below code and I am not able to continue the session once I use this SCRIPT below.

var timerObj;
function SetTimer(){
//How long before timeout (should be a few minutes before your server's timeout
var dblMinutes = .1;
//set timer to call function to confirm update
timerObj = setTimeout("ShowTimeoutWarning()",1000*60*1);
}

function ShowTimeoutWarning ()
{
if (confirm("Your session is about to expire. Press 'OK' to renew your session.")) {
window.location.href = window.location;
window.alert("YES");
window.alert("window.location = "+window.location);
window.alert("window.location.href = "+window.location.href);
//document.searchQuery.submit();
} else {
window.location.href = "login.jsp";
window.alert("NO");
}
}
//start the timer
SetTimer();

Help me out on how to generate a popup when the session timeout happens and when clicking OK it should continue the session and when I click NO it should take me to the login.jsp page.

waiting for a reply.
thanks,
KP
 
g madhava
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are couple of problems with your approach.
The first thing, you are relying on javascript to do the session handling for you. Let's say if the application server (or the web server, whatever may be the case) stops running,then how can your javascript guarantee that the session is still valid ? Your IF loop in the javascript would assume that the session is still valid.

If you can post your java code as well as the JSP code, might be we can help you more.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!