2

I'm writing a web app with multiple jsp files wit a session timeout of 20 min. But in a specific jsp when i call an action i need to set the session timeout bigger. I use: request.getSession().setMaxInactiveInterval(1800);

Then one the action it's ended i reset the session timeout to it's original value with: request.getSession().setMaxInactiveInterval(600);

But when running the app, and calling the action, one it ends the session close 'cause the time i set have already passed.

What i want to know is if there is a way no know when i exit jsp? not closing the brower or closing the tab windows. For example, i call another jsp?.

Or is another way to resert the session timeout so the session doesn't close when the action end?

I forgot. The action is inside a for bucle and if a condition if true the action if called. And i put the code changing the session timeout before calling the action and reset the time when the action ends.

for(int i = 0; i < totalreg; i++) {
    if (condition) {
        request.getSession().setMaxInactiveInterval(1800);
        process();
        request.getSession().setMaxInactiveInterval(600);
    }
}

Thanks.

  • When you move to other jsp you explicitly code that right? Why not add this line at that particular code? – kosa Feb 15 '12 at 15:03

2 Answers2

1

Just have an invisible/very small iframe where you reload some random page continously. Alternatively you could use AJAX for that purpose. This way your session will never time out as long as this page is open.

It's also a good way to show progress of your action asynchronously.

Simon
  • 1,814
  • 20
  • 37
  • Thanks for the answer, but for waht i'm doing the invisible iframe will not be acceptep. About using ajax, how can i do it?. I have to say i'm just a begennir in this. – Leonardo Reyes Feb 19 '12 at 20:47
  • Can you tell why using a refreshing iframe to keep the session alive is no good? AJAX wouldn't work much different and probably lead to the same problems, whatever they may be. – Simon Feb 19 '12 at 21:49
  • It's more policy company that functionality. – Leonardo Reyes Feb 20 '12 at 16:52
  • Ok, weird company... Here's an [article](http://www.atalasoft.com/cs/blogs/jake/archive/2008/12/19/creating-a-simple-ajax-keepalive.aspx) that explains one technique. Complete code in the last paragraph. – Simon Feb 20 '12 at 17:53
0

I found what i was lookin with javascript using the onbeforeunload event. I found in this website in this link: Best way to detect when user leaves a web page.

Community
  • 1
  • 1