这儿有一段话,解释比较详细:The sessions are linked to the client. If you start IE and then use
Ctrl-N to open a new window in the same process, it will share the same
session. You can check if a new process is started by using Windows'
task manager, and check how many instances if IEXPLORE you have in the list.However, if you start IE and then again by double-clicking on the IE
icon on your desktop, for example, then you will have two separate
processes, and the sessions won't be shared.excerpt from: http://www.velocityreviews.com/forums/t363555-session-being-kept-from-brower-to-browser.html
Ctrl-N to open a new window in the same process, it will share the same
session. You can check if a new process is started by using Windows'
task manager, and check how many instances if IEXPLORE you have in the list.However, if you start IE and then again by double-clicking on the IE
icon on your desktop, for example, then you will have two separate
processes, and the sessions won't be shared.excerpt from: http://www.velocityreviews.com/forums/t363555-session-being-kept-from-brower-to-browser.html
解决方案 »
- |.NET转Java|在C#中给字段添加特性和取得特性内容在JAVA中是怎么做的,谢谢
- S2SH整合报错Constructor threw exception
- 关于struts传递参数是乱码
- 用EJB存储CLOB遇到:[java.sql.SQLException: Could not get java.sql.Clob to write to]异常
- 高手请进:关于javamail的一个问题
- 用Java开发了个WebService,在VB,Delphi下怎么调用啊?
- 请教各位大侠了,我的毕业设计是<基于Web Services的教学网站>,我是一头雾水!
- Java初学者,询问Java的流行技术,及学习方向(高分)。
- 关于eclipse3.0+weblogic8.1的配置问题,高分求助!!!
- Weblogic如何改变默认的文件存放路径?
- java中使用soap的问题
- JSP页面之间参数如何传递?
理解session机制
session机制是一种服务器端的机制,服务器使用一种类似于散列表的结构(也可能就是使用散列表)来保存信息。当程序需要为某个客户端的请求创建一个session的时候,服务器首先检查这个客户端的请求里是否已包含了一个session标识 - 称为 session id,如果已包含一个session id则说明以前已经为此客户端创建过session,服务器就按照session id把这个 session检索出来使用(如果检索不到,可能会新建一个),如果客户端请求不包含session id,则为此客户端创建一个session并且生成一个与此session相关联的session id,session id的值应该是一个既不会重复,又不容易被找到规律以仿造的字符串,这个 session id将被在本次响应中返回给客户端保存。保存这个session id的方式可以采用cookie,这样在交互过程中浏览器可以自动的按照规则把这个标识发挥给服务器。一般这个cookie的名字都是类似于SEEESIONID,而。比如weblogic对于web应用程序生成的cookie,JSESSIONID= ByOK3vjFD75aPnrF7C2HmdnV6QZcEbzWoWiBYEnLerjQ99zWpBng!-145788764,它的名字就是 JSESSIONID。更多请参考:http://www.idosoft.com.cn/techgather/12.html
再问一个问题
public class CompleteServlet extends HttpServlet implements Servlet { private static int count = 0;
private static Cookie cookie = null;
/**
* @see javax.servlet.http.HttpServlet#void (javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
testCookie(req, resp);
//testRequest(req, resp); }
public void testCookie(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
if (cookie == null) {
//Create a Cookie
cookie = new Cookie("mycookie", "j2ee");
//set age
cookie.setMaxAge(60*2);
//use the Cookie
resp.addCookie(cookie);
} else {
/*test cookie*/
//Obtain all cookies
Cookie[] cookies = req.getCookies();
//display mycookie
/*Generate Dynamic Content*/
resp.setStatus(HttpServletResponse.SC_OK);
resp.setContentType("text/html");
PrintWriter out = resp.getWriter();
out.println(
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD "
+ "HTML 4.0 Transitional//EN\">");
out.println("<HTML><HEAD><TITLE>Complete Servlet</TITLE></HEAD>");
out.println("<BODY>");
out.println("<H1>The following information are about Cookies</H1>");
//prevent dead cookie
if (cookies != null) {
for (int i = 0; i < cookies.length; i++) {
String cookieName = cookies[i].getName();
out.println("<br>" + cookieName);
if (cookieName.equals("mycookie")) {
out.println("<br>mycookie is " + cookies[i].getValue());
}
}
} else {
out.println("cookies have been destroyed");
}
out.println("</BODY></HTML>");
}
}
/**
* @see javax.servlet.http.HttpServlet#void (javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
}
第一次访问CompleteServlet时,打开一个IE浏览器会收到一个cookie,第二次访问时就会显示出如下效果:
mycookie
mycookie is j2ee
两分钟之后再次访问
出现如下结果:
cookies have been destroyed
这是我双击打开另一个IE浏览器,输入URL访问CompleteServlet,结果还是:
cookies have been destroyed
我搞不懂了,这是为什么?既然两次打开浏览器是两次session,那为什么双击打开另一个IE浏览器却找不到cookie呢?
调试运行,发现第二次打开浏览器的时候,确实会进入cookie==null中,运行cookie=new Cookie,可是却找不到,这又是为什么呢?请大家帮帮忙了!!
这样只有1个session。
自己可以试验的,首先启动IE(我的是IE7),打开CSDN,登录。然后,新建一个空标签页,打开CSDN,你会发现你已经登录啦,所以,这2个页面是共享同一个SESSION的。希望下面的2篇文章能帮助你理解SESSION:
http://www.builder.com.cn/2007/0728/438360.shtml
http://baike.baidu.com/view/25258.htm
开两次浏览器就相当于建立了两个会话,也就是两个session啦.
这两个session的id是不同的,楼主可以打印下就知道啦.
比如:CSDN就是同一个Session
但是有的网站还可以同时打开几个浏览器同时登录!~!
你看看这个网页吧,真的还不错
http://www.builder.com.cn/2007/0728/438360.shtml
打开两个ie7算两个session
数据是不一样的