JSF - 会话管理
当我打开两个浏览器并并行输入详细信息时,这些值会变得混合。一个浏览器中的值填充在另一个浏览器中...我们正在使用 JSF 框架,托管 bean 位于会话范围内(在我们的情况下不可能将它们放在请求范围内)...简而言之,这些值是跨浏览器共享...如何避免这种情况?有什么线索吗?
When I open two browsers and enter details parallely, the values are getting mixed. The values in one browser are populated in the other browser... We are using JSF framework and the managed beans are in session scope (having them in request scope is not possible in our case)... In a nutshell, the values are shared across the browsers... How to avoid this? Any clue?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您“打开两个浏览器”意味着您打开同一浏览器的两个窗口,那么一切都是正确的 - 每个浏览器只能获得一个会话(对于 Firefox,有一个插件可以避免这一限制)。
但是,如果您实际上使用两个不同的浏览器,而不是在这种情况下,您会将所有数据保存在应用程序范围内,否则您的容器就会出现问题。
If you "open two browsers" means you open two windows of same browser then everything is correct - you can get just one session per browser (for firefox there is plug-in which allow to avoid this limitation).
But if you use really two different browsers than in this case seams you save all data in application scope or you have a problem with you container.
您需要将 bean 放入请求或视图范围内。正如您所遇到的那样,将基于请求/视图的数据存储在会话作用域 bean 中是一个坏主意。
我认为视图范围会有很大帮助,因为您提到请求范围“不可能”(实际上是这样,它只需要预加载正确的数据,以便 JSF 可以相应地采取正确的操作)。
You need to put the bean in request or view scope instead. Storing request/view based data in a session scoped bean is a bad idea, as you've encountered yourself.
I think the view scope would help a lot, given the fact that you mentioned that the request scope is "not possible" (it actually is, it only requires preloading the right data so that JSF can take the right actions accordingly).