小弟遇到个问题、真心求教。
我有二个程序、分别放在两台服务器上。一台是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丢失。
我有二个程序、分别放在两台服务器上。一台是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丢失。
嗯。我在访问另一个服务器上程序的时候,先去调用创建session的方法,然后再重定向到目标页面。
我也不需要二个程序用同一个session。主要是能打开另一个服务器上的程序就可以了。
其实是这样的。我这新开发了部分 2.0程序。而一部分还是要用老的1.0程序,所以我要通过iframe,访问老的程序。
换成请求跳转看看试试。。如表单提交。。或者servlet跳转。。
public class CreateNewSession extends Action{
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
response.setContentType("text/html");
response.setCharacterEncoding("gbk");
PrintWriter out = response.getWriter();
Js_Func js = new Js_Func();
GLOBAL_PARA para=new GLOBAL_PARA();
/*********数据同步***************************/
String Jalert = "";
String CsUserName=request.getParameter("CsUserName");
String CsPassWord=request.getParameter("CsPassWord");
String RequestPath=request.getParameter("RequestPath");
String queryString=request.getQueryString();
String path = request.getContextPath();
String basePath = request.getScheme() + "://"+ request.getServerName() + ":" + request.getServerPort()+ path + "/";
String gotourl = basePath + "message.jsp";
RequestPath=basePath + RequestPath+"?";
String RequestBasePath=dealQueryString(queryString,RequestPath);
String hasLogin = (String) request.getSession().getAttribute("hasLogin");
if(null==hasLogin||"".equals(hasLogin)){
UserService userservice = new UserService();
User user = userservice.getUser(CsUserName, CsPassWord);
if(null==user){
Jalert = js.alert("用户名或密码传送有误!");
Jalert = js._Write("location.href='"+gotourl+"'");
}else{
if(null!=RequestBasePath&&!"".equals(RequestBasePath)){
HttpSession session = request.getSession();
session.setAttribute("user", user);
session.setAttribute("hasLogin", para.getPowername());
Jalert = js._Write("location.href='"+RequestBasePath+"'");
}else{
Jalert = js._Write("location.href='"+gotourl+"'");
}
}
}else{
if(null!=RequestBasePath&&!"".equals(RequestBasePath)){
Jalert = js._Write("location.href='"+RequestBasePath+"'");
}else{
Jalert = js._Write("location.href='"+gotourl+"'");
}
}
out.print(Jalert);
out.flush();
out.close();
return null;
}这是我创建session,然后跳转的代码。
解决方案:
session复制
即使是集群下,目前也没有很完美的session传递方案其实,很多数据都可以附加在url上,标准url能支持4000个字符,足够传递一些常规信息了
你可以看看淘宝之类的网站,都是在url上附加了一大堆的消息
那2台不同服务器上的tomcat可以设置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复制和共享。