2016-06-22 88 views

回答

0

嘗試使用JavaScript顯示彈出一旦計時器到期此處超時存儲超時期限,現在運行計時器,並顯示一旦計時器到期彈出。下面的演示代碼,但你必須定製它,它不是完整的代碼。

 var timeout=<%= currentUser.getSession().getTimeout() %>; 
     var starttimer=timeout-60000; //+100000000; 
     var timerstep=1;//In minutes 
     var alertbefore=5;//In minutes 
     var logoutUrl="logout";//Url to logout 
     var militimerstep=timerstep*60*1000; 
     var sessionNoExpireMessage="Session will never expire!!!"; 

var sess_timer=window.setInterval(updateTimer,militimerstep); 
    $("#timeout_timer").html(moment.duration(parseInt(starttimer,10)).humanize(true) + " remaining "); 
    if(timeout<0) 
    { 
     clearInterval(sess_timer); 
     $("#timeout").html(sessionNoExpireMessage+ " remaining "); 
    }else{ 
     $("#timeout").html(moment.duration(parseInt(starttimer,10)).humanize() + " remaining"); 
    } 
    function updateTimer(){ 
    console.log("In timer"); 
    // alert(timeout); 
    if(timeout<0) 
     { 
      clearInterval(sess_timer); 
      $("#timeout").html(sessionNoExpireMessage); 
      return false; 
     } 

     starttimer = starttimer-militimerstep; 
     $("#timeout").html(moment.duration(parseInt(starttimer,10)).humanize() + " remaining"); 
     $("#timeout_timer").html(moment.duration(parseInt(starttimer,10)).humanize(true)); 
     if(starttimer<=0){ 
      window.location.replace("${pageContext.request.contextPath}/"+logoutUrl); 
      window.location("${pageContext.request.contextPath}/"+logoutUrl); 
     } 
     if(starttimer<alertbefore*60*1000){ 
      $("#session_alert").modal(); 
     } 
    } 

    function updateSessionInfo(){ 
     if(timeout<0) 
     { 

      return false; 
     } 
     ajaxCount--; 
     resetajaxView(); 
     starttimer=timeout-60000; 
     $("#timeout").html(moment.duration(parseInt(starttimer,10)).humanize() + " remaining"); 
     $("#timeout_timer").html(moment.duration(parseInt(starttimer,10)).humanize(true)); 
    }