日期:2014-05-17  浏览次数:20973 次

求助!关于两服务器间,session的问题。
小弟遇到个问题、真心求教。


我有二个程序、分别放在两台服务器上。

一台是192.168.89.15 (A) 另一台是 192.168.89.233 (B)


然后我在(A)登陆之后,通过框架,要把(B)的部分程序Iframe进来。


然后我在(A)程序上,加了iframe ,链接如下(创建B的session,然后location.href到目标地址)
http://192.168.89.233:8080/emr/createnewsession.do?CsUserName=000042&CsPassWord=000&RequestPath=emr/ipd/UIIpd_In_Reco.jsp&dateseq=2010100600020&cht_id=60019097&Flag=Ymethod=ipd_cht&dateseq=2010100600020&cht_id=60019097


现在问题是 :iframe里面创建session完成后,location.href到目标页面,session丢失。




------解决方案--------------------
location.href是js的get方式跳转吧。。。这样还在上下文范围么?
换成请求跳转看看试试。。如表单提交。。或者servlet跳转。。
------解决方案--------------------
LZ一个浏览器在不同的服务之间切换,因为浏览器会在请求后发送JSESSIONID,不切换的话,不丢失,切换的话,发送的另一个服务器的,肯定会session丢失。
解决方案:
session复制

------解决方案--------------------
跨域访问就不要以基于session的数据保存方案了
即使是集群下,目前也没有很完美的session传递方案

其实,很多数据都可以附加在url上,标准url能支持4000个字符,足够传递一些常规信息了
你可以看看淘宝之类的网站,都是在url上附加了一大堆的消息
------解决方案--------------------
如果是用tomcat的话
那2台不同服务器上的tomcat可以设置session共享
------解决方案--------------------
关于session的维护:
HTTP is a state-less protocol, means that it can't persist the information. It always treats each request as a new request.

In Session management Client first make a request for any Servlet or any page, the Container receives the request and generate a unique Session ID and gives it back to the Client along with the response. This ID gets stores on the Client machine. Thereafter when the Client request again sends a request to the Server then it also sends the Session ID with the request. There the Container sees the ID and easily identifies the Session associated with that Client.

Session-Tracking can be done in 3 ways :

1. Hidden Form Fields
2. Cookies
3. URL Rewriting

一客户端对多域的这种情形,我觉得也是可以共享session的,当客户端第一次请求陌生域时,就带上老的session id,而域与域之间对于session相关的数据也应该是有个提前共享机制,就像上面说的session复制和共享。