File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Session counter: ok Mozilla, !ok in IE Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Session counter: ok Mozilla, !ok in IE" Watch "Session counter: ok Mozilla, !ok in IE" New topic

Session counter: ok Mozilla, !ok in IE

M. Pr�pper

Joined: May 17, 2004
Posts: 4
Hi, I tried a simple counter that persists using a HttpSession object very similar to that in post 'Session Tracker' somewhat lower in the list. It works fine in Mozilla: refreshing increments the counter, upon opening a second browser the same counter (same ID) starts at the incremented value and after closing all windows and restarting the counter the value is also ok.

In internet explorer only refreshing (F5) works. Upon opening a second window a second counter is started (new session, new ID)! Two counters work in parallel now. After closing all windows and restarting a new counter (sessions) starts, too.

Does anybody recognize this behaviour and what setting in IE causes this behaviour?
Thanks for answering, Marc
damien malone
Ranch Hand

Joined: May 06, 2003
Posts: 35

In IE, the second window has to be opened by the first window (javascript or href to a new window) or by selecting 'file', 'New', 'Window' (or ctrl+n) for a new window to open that is in the same session as the first window. If you just simply click on the ie icon, the second window will be opened, but with a new session.

The have to press 'F5' is got to do with your browser settings, select 'Tools', 'Internet Options'. In the temporary files section on the general tab, select 'settings. Check here that your browser always looks for new versions of a page, rather than reading it from the cache.

Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63873

In IE, the second window has to be opened by the first window

The reason for this has to do with the way IE shares cookies. Since the session is kept track of via a cookie, windows that share cookies will share a session, while windows that do not share cookies will not share the session.

[Asking smart questions] [About Bear] [Books by Bear]
M. Pr�pper

Joined: May 17, 2004
Posts: 4
Opening a new window from within the main window works fine indeed.

Then, I changed the setting as suggested to search always for a newer file. No caching. Upon opening a new window from the launch bar the counter has the correct value. But an F5 refreshing restarts the counter at its initial value. Strange. Further refreshing through F5 makes the counter increment as usual.

The applicability of a session object seems more limited than I'd hoped. In mozilla I can set the maxInactiveInterval at -1 (no automatic invalidation after a certain time), close all windows, restart the server and still the session persists (quite surprised that it holds even after restarting the server).

Thanks for answering, Marc
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
Actually, IE has the correct behaviour while Mozilla does not...

Session should be bound to browser instance, not browser window instance as is the case with Mozilla.

I agree. Here's the link:
subject: Session counter: ok Mozilla, !ok in IE
It's not a secret anymore!