java - Extending session time out for ajax based file upload -


i using spring security in application , session time out 30 min. , using ajax call in front end.

my issues are:-

problem-1 doing .xml file uploading through ajax call take more 30 min may b take 1 hour(it depends on file size). how handle session time out ajax call in spring security or other way? because after file uploaded redirect me login page don't need this. want update session in server side while ajax call happening in application.

please me solve issue.

ajax code

function uploadform() {

        if ($('div.bootstrap-filestyle').find('input[type="text"]')                 .val() == "") {             alert("no file selected");         } else {             var selectedactionurl = $("#drplink").val();             console.log(selectedactionurl);             var url = "";             if (selectedactionurl == 1) {         url = "${pagecontext.request.contextpath}/excellupload";             }               console.log('file uploading..');             var $statusmsgdiv = $('div#status-msg');             $('#result').html('');             var $uploadfrm = $("#uploadform");             $uploadfrm.attr('action', furl);             $uploadfrm.ajaxform(                 {                 beforesend : function() {                     //some logic                     },                 success : function(jsonres) {                 //some logic                 },                 error : function(xhr, textstatus,errorthrown) {                 //some logic                  }).submit();         }         return false;         } 

server side code

web.xml file

//..... code
login.jsp

<error-page>     <error-code>404</error-code>     <location>/404</location> </error-page>  <session-config>     <session-timeout>30</session-timeout>     <tracking-mode>cookie</tracking-mode> </session-config> 

problem 2

should need update session time out value each time in fileupload controller or need write other controller can serve ajax request or response ? please me fix issue. in advance.....

for file upload take 5 8 hour want dynamically when ajax request going on server don't want session time out. after user stay idle 30 min out db hit/ajax call time need session time out.

<session-config>     <session-timeout>30</session-timeout>     <tracking-mode>cookie</tracking-mode> </session-config> 

when configure session timeout in web.xml, in scenario session timeout if period of inactivity between client & browser more 30 mins. if there request client within these 30 mins. session again reset it's timeout counter further 30 mins. if don't configure session-timeout there default server session timeout time interval. tomcat it's 30 mins, server automatically invalidate session after 30 mins of inactivity.

now regarding ajax file upload process if there continuous interaction between client & server. session not time out. sessions in web applications time out because of 2 reasons 1. security 2. inactivity, resources allocated session can reclaimed if client doesn't require them anymore.

programmatically ajax request can set session time out

httpsession session = request.getsession(); session.setmaxinactiveinterval(20*60); 

which takes precedence on web.xml configuration.

you can implement cookie based session persistence

yes tried multiple times it's redirecting login page after file upload success/failure.(when file upload take more 30 min.

you need create heartbeat interceptor between client & server. in same ajax call upload file. have send request server periodically after every n seconds/mins keep session alive. create callback function in ajax stops sending requests once file uploaded on server. check this & this


Comments