views:

144

answers:

2

I set session timeout to be 5 minutes in web.xml. And once session expired sessionDestroyed() will be executed.

But I want session to be alive as long as browser window is still there. So in each JSP page there is a piece of JavaScript code that visits an image on the server every 100 seconds. Basic idea regarding this part can be found at http://www.intelliproject.net/articles/showArticle/index/js_session_expired

However, the sessionDestroyed() will still be executed in 5 minutes. Here is my question, why sessionTimeout event is triggered even though I keep visiting it every 100 seconds?

+3  A: 

Using firebug, open the net tab and watch for the javascript request. You should be receiving HTTP 200 for each image GET, and each url should have random numbers appended to the end. You should probably just use a timestamp, rather than random numbers, as random numbers might eventually repeat and log the user out.

Do you have an example page where this is happening?

Stefan Kendall
Thank you for your reply. I've made this test page for you:http://secure10.olemiss.edu/hdstore/test.jspBut I don't think it helps.
David
Check the web.xml contents here: http://secure10.olemiss.edu/hdstore/test.jsp
David
+2  A: 
  1. make sure your js call executes - there are no js errors (see error console), and that 200 is returned
  2. Do not use random parameter at the end of the image - this is not guaranteed to bypass the cache. Istead set the Expires / Cache-Control headers of the accessed resource
  3. Don't use an image, use an empty text (jsp) file. You can also manually set the headers there.
Bozho
Thanks. Could you tell me how to check '200 is returned'?
David
As Stefan Kendall advised - use firebug
Bozho
I tested it and 304 is returned. Make use of a Filter or a dummy JSP page which has the right response headers to disable caching of the request.
BalusC
I tested it, and I'm getting 200.
Stefan Kendall
@Bozho: Are you sure it shouldn't bypass the cache? Using a timestamp DEFINITELY does (as it's the ONLY way to get IE6 to not cache certain items, because it ignores headers), and aside from the "0." in front of the number, the random number generator is almost like using a timestamp (but not 100% reliable).
Stefan Kendall
well, I'm not quite sure actually. http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html#sec13.9 That's the spec, what can you infer from it?
Bozho