如何在不同的浏览器标签页的会议? [英] How to differ sessions in browser-tabs?

查看:105
本文介绍了如何在不同的浏览器标签页的会议?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用JSP和Servlet的Java实现的web应用程序;如果我在用户会话存储信息,该信息是从相同的浏览器的所有选项卡共享。如何在不同的浏览器标签页的会议?
在这个例子中:

In a web-application implemented in java using JSP and Servlets; if I store information in the user session, this information is shared from all the tabs from the same browser. How to differ sessions in browser-tabs? In this example:

<%@page language="java"%>
<%
String user = request.getParameter("user");
user = (user == null ? (String)session.getAttribute("SESSIONS_USER") : user);
session.setAttribute("SESSIONS_USER",user);
%>
<html><head></head><body>
<%=user %>
<form method="post">
User:<input name="user" value="">
<input type="submit" value="send">
</form>
</body></html>

在JSP页面中( testpage.jsp ),部署在现有的背景下,这个文件webaplication服务器(我用的Apache Tomcat),然后复制此code打开使用正确的网址浏览器(FF,IE7或Opera)(本地主机/ CONTEXT1 / testpage.jsp ),输入您的姓名和提交表单。然后打开在同一个浏览器的新选项卡,然后就可以看到你的名字(从会话获取)的新标签。小心浏览器的缓存,有时似乎它不会发生,但它的缓存,刷新了第二个选项卡。

Copy this code in a jsp page (testpage.jsp), deploy this file in existing context on a webaplication server (I use Apache Tomcat), then open a browser(FF, IE7 or Opera) using the correct url (localhost/context1/testpage.jsp), type your name in the input and submit the form. Then open a new tab in the same browser, and then you can see your name (get from the session) on the new tab. Be careful with the browser-cache, sometimes seems that it doesn't happen but it's for the cache, refresh the second tab.

THX。

推荐答案

您可以使用HTML5的sessionStorage(window.sessionStorage)。您将生成一个随机ID,并保存在每个浏览器选项卡会话存储。
然后,每个浏览器选项卡都有自己的编号。

You can use HTML5 SessionStorage (window.sessionStorage). You will generate a random id and save in session Storage per Browser Tab. Then each browser tab has his own Id.

使用sessionStorage的跨浏览器标签页不会持续存储数据,
  即使两个选项卡都包含来自相同域出身的网页。在
  换句话说,内部的sessionStorage数据被限制到不只是
  域和调用页面的目录,但是在浏览器标签
  该页面包含在,对比度,为会话cookie,
  它坚持做从标签数据标签。

Data stored using sessionStorage do not persist across browser tabs, even if two tabs both contain webpages from the same domain origin. In other words, data inside sessionStorage is confined to not just the domain and directory of the invoking page, but the browser tab in which the page is contained in. Contrast that to session cookies, which do persist data from tab to tab.

这篇关于如何在不同的浏览器标签页的会议?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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