在不使用会话上下文的情况下在Web应用程序中保留值 [英] Persist a value in an web application without using the session context

查看:76
本文介绍了在不使用会话上下文的情况下在Web应用程序中保留值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个变量",用户可以在JSP/Struts应用程序中进行修改,该变量必须在整个Web应用程序会话中保持不变.他们可能会离开设置和查看页面的页面(仍然停留在应用程序中),并且当他们返回该值时,它们最后一次为该变量设置的值仍然应该存在.

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.

显而易见的选择是将其存储为会话属性.那就是我几年前要做的.但是,Internet Explorer 8和更高版本会导致Web应用程序用户为在同一站点打开的所有浏览器进行一个会话.换句话说,如果用户在浏览器中打开我的应用程序,然后在另一个浏览器中再次打开它,则他们共享一个会话.我想他们正在共享代表该会话的cookie.结果是,如果他们在一个浏览器的会话中更改了该值,那么在另一个浏览器中该值也将被更改.

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.

我的用户将在单个工作站上多次运行该Web应用程序,我需要他们能够在其不同的浏览器窗口(甚至标签)中为上述变量设置不同的值,并具有不同的值在该浏览器(或标签)的生存期内保持不变,但不会影响到同一应用程序的任何其他打开的浏览器(或标签).

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.

据我所知,使用会话属性是不可能的. (嗯,有IE -nomerge选项,但是无法强迫用户使用该选项启动IE.)

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.

推荐答案

如果所有选项卡或窗口都发送回相同的会话ID,则服务器无法区分它们.但是,如果您需要那种功能,那么我会考虑在URL中建立差异".例如,一个选项卡可能具有/myapp/xxxxx/,而另一个选项卡可能具有/myapp/yyyyy/.可能会共享同一个会话,但是服务器仍可以区分它们. URL的实际格式并不十分重要,只要浏览器始终在某个地方返回魔术部分(例如:xxxxx)即可.在服务器端,您可以根据sessionid和发出请求的URL跟踪每个会话的多个号码.

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.

唯一要决定的事情是,您如何注意到新的选项卡或窗口已打开,因为您必须分配一个新的URL,但这仅仅是一个问题.例如,您可能有一个本地js变量,需要将其设置为与URL匹配,然后在打开新标签页时此变量将不匹配,因此您可以转到新的适当的URL并设置本地变量.

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.

这篇关于在不使用会话上下文的情况下在Web应用程序中保留值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆