• Post Reply Bookmark Topic Watch Topic
  • New Topic

session timeout using javascript  RSS feed

p kiran
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using JSF, I want to logout a user once the user session timeout happens. I did add the following tag;
session-timeout 5 session-timeout
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("window.location = "+window.location);
window.alert("window.location.href = "+window.location.href);
} else {
window.location.href = "login.jsp";
//start the timer

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.
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.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!