Reputation: 4349
I have a "variable" that users can modify in a JSP/Struts application that must be persisted across that entire web application's session. They may navigate away from the page where it is set and viewed (still staying in the application), and when they come come back the value they last set for that variable should still be present.
The obvious choice would be to store it as a session attribute. And that's what I would have done a few years ago. But Internet Explorer 8 and higher cause a web app user to have one session for all browsers that are open to the same site. In other words, if a user opens my application in a browser, then opens it a second time in another browser, they share a single session. I presume they are sharing the cookies that represent that session. The result is if they change the value in one browser's session, that value will then be changed in the other browser as well.
My users will run the web app multiple times on a single workstation, and I need for them to be able to set different values for the above mentioned variable in their different browser windows (or even tabs), and have the different values persist for that browser (or tab) lifetime, but not affect any other open browsers (or tabs) to the same application.
So, as far as I can tell using session attributes is out of the question. (Well there is the IE -nomerge option, but there is no way to force the users to launch IE using that option).
I am hoping I am not the first to deal with this issue, and someone out there has solved it elegantly, and that person reads this post and responds.
Upvotes: 2
Views: 672
Reputation: 1865
There is no way for the server to distinguish different tabs or windows if they all send back the same session id. However, if you need that kind of functionality then I would consider building the "difference" into the URL's. For example, one tab might have /myapp/xxxxx/, while a different tab might have /myapp/yyyyy/. The might both share the same session but the server can still distinguish between them. The actual format of the URL is not really important so long as the browser always returns the magic part (eg: xxxxx) somewhere. At the server end of things you can keep track of multiple numbers per session based on the sessionid and the URL that is making the request.
The only thing to decide is how you notice that a new tab or window has opened, as you have to assign a new URL, but that's just plumbing. For example, you could have a local js variable which needs to be set to match the URL, then when a new tab opens this variable will not match so you can then go to a new appropriate URL and set the local variable.
Upvotes: 2