Sunday, April 28, 2013

Extends Session Time for Every Request

Extend Session
Why I worte this post?


1. After loging application, session time starts {Session Time}
2. For example, Session time set as 30 It means, your Session will validate after 30minutes late from first login
3. if you want to extends session time from some request within 30minute
4. you have to add duration from
4. below is solution to extends session time
// this is the time session created
long createdtime=session.getCreationTime();
// current Time
long currentTime = System.currentTimeMillis();
long lastAcessedTime = session.getLastAccessedTime();
// duration from first session created
int duration= (int)((currentTime - lastAcessedTime)/1000);
// session time
int inactive=session.getMaxInactiveInterval();
// set new session time (duration + original session Time)
request.getSession().setMaxInactiveInterval(duration+ inactive);


No comments:

Post a Comment