0
votes

I've a web page, where user can extend the session using AJAX call to server. If the application configured session timeout is for 30 minutes, he can extend the session for 5 minutes by pressing a button. When this user submits the pages, I need to reset this session timeout value back to the global session-timeout value.

Is it possible in Java to reset it? or Is it possible to read the global session-timeout value which is configured in web.xml?

EDIT:

I'm using the following code to extend the session

request.getSession().setMaxInactiveInterval(300000);
3

3 Answers

0
votes

How do the user extend the session. I mean do you give a javascript alert/confirm box regarding it.

Ideally, session should automatically be extended when the user submits a request to the server.

setMaxInactiveInterval() in code and <session-config> in web.xml should do the stuff in normal scenario.

Share the exact situation of your application

EDIT: Sending a dummy request to a JSP should automatically extend the session as session time out is measured in terms of inactive interval and the dummy request should discard the inactive interval till now.

0
votes

I solved it by setting the default session as a session variable on execution of an action class, then using it to reset when ever required. I'm not sure this is the right way to solve this. but it solve my issue, at least for now.

0
votes

The time out and rest function is here and it will work accordingly to the service response.

Time setting function:

$rootScope.SessionTime =localStorage.getItem('mint');
           $rootScope.tickDuration=1000;
                $rootScope.myInterval=setInterval(function(){

                  $rootScope.SessionTime=$rootScope.SessionTime-$rootScope.tickDuration
                  //console.log("secs:::::"+$rootScope.SessionTime);
                 if($rootScope.SessionTime<300000 && $rootScope.tickDuration >0){
                    $('#session').modal('show');
                    $rootScope.tickDuration =0;
                 }
           },$rootScope.tickDuration);

Time out function:

 $scope.myTimeout = function(){            
           var sessionId=getcokkies.getsessionId(); 
           $http({
                   url: config.apiUrl + '/user/refreshsession?sessionId='+sessionId,
                 method: "POST",
                   headers: {
                       'Content-Type': 'application/x-www-form-urlencoded'
                   },
                   data: $.param({
                       'userId': parseInt(getcokkies.getUserId()),
                   })
               }).then(function successCallback(response) {
                   //localStorage.setItem("mint", 600000);
                    //$rootScope.SessionTime = 600000;
                   clearInterval($rootScope.myInterval); 
                   localStorage.setItem("mint", 600000); 
                   $rootScope.SessionTime =localStorage.getItem('mint');
                  // console.log("after++++"+$rootScope.SessionTime);
                   $rootScope.tickDuration=1000; 


               }, function errorCallback(response) {});

           }