HttpSession的实现和cookie机制
java web服务器通过实现httpsession来保存客户端的状态(jsessionid),也就是我们通常说的session。session是通过cookie机制来实现(网上说如果客户端禁用了cookie,则可以通过url重写来实现,一会再讨论。。)。
1、session的生成
在客户端第一次请求jsp页面,或servlet时生成,并向客户端写一个标识,即:jsessionid
由请求返回的http协议串可以看出:
请求:POST /ibsm/LoginAction.do HTTP/1.1Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*Referer: http://192.168.3.197:8080/ibsm/Accept-Language: zh-cnContent-Type: application/x-www-form-urlencodedUA-CPU: x86Accept-Encoding: gzip, deflateUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.2; .NET CLR 1.1.4322; .NET CLR 2.0.50727)Host: 192.168.3.197:8080Content-Length: 42Connection: Keep-AliveCache-Control: no-cachecode=lyc&password=123&actType=ywgl&userId=响应:HTTP/1.1 200 OKServer: Apache-Coyote/1.1Set-Cookie: JSESSIONID=1442A671BEEDA147A2756B7E083D3B7E; Path=/ibsmContent-Type: text/html;charset=GBKContent-Length: 436Date: Mon, 01 Feb 2010 05:18:06 GMT
GET /ibsm/ApplicationFrame.frame HTTP/1.1Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*Accept-Language: zh-cnUA-CPU: x86Accept-Encoding: gzip, deflateUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.2; .NET CLR 1.1.4322; .NET CLR 2.0.50727)Host: 192.168.3.197:8080Connection: Keep-AliveCookie: JSESSIONID=1442A671BEEDA147A2756B7E083D3B7E
GET /ibsm/ApplicationFrame.frame?block=menuFrame HTTP/1.1Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*Referer: http://localhost:8080/ibsm/ApplicationFrame.frameAccept-Language: zh-cnUA-CPU: x86Accept-Encoding: gzip, deflateUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.2; .NET CLR 1.1.4322; .NET CLR 2.0.50727)Host: localhost:8080Connection: Keep-AliveCookie: JSESSIONID=191861A4C2331978793F62DD585CC2F010 楼 zhouweijava 2010-02-04 robertliudeqiang 写道可能对