window.open() clears session

耗尽温柔 提交于 2019-12-11 18:54:31

问题


I have several portlets in my application. If I open a url using window.open() method, the session id changes and causes an error in other portlets. If I don't open this url, everything works fine. But once this new window is opened, the session is cleared and the rest of the portlets throws an exception since some values are missing. In the address bar of the browser I typed in javascript:alert(document.cookie); to see the JSESSIONID. It remains constant throughout the page and changes when I click the link that launches a new url in new window. I used IE8.

Any suggestions to maintain the session state in IE would be greatly appreciated.


回答1:


What URL are you passing to window.open()? An easy way to get IE 8 to maintain the JSESSIONID in the popup would be to use a relative URL in the call to window.open() in the portlet markup. The critical thing is that the domain name remain exactly the same. Here's an example of a button with window.open() in the onclick event:

<button onclick="javascript:window.open('/wps/portal')">Home Page</button>

I'm using Websphere Portal, so '/wps/portal' just links to the home page.

Also, what do you intend to be the target of the popup window? A different portal page with the same session?

Update: Given that the target of the window.open() is an independent web application hosted on the same domain...

The portal server and the application server hosting the web application have independent sessions, but they both use a cookie called JSESSIONID by default. The first time you access the web application, the application server overwrites the portal's cookie, causing every subsequent request to the portal to have the wrong session id. When this happened to me, my solution was to configure the portal to name its session cookie something else (e.g. PORTALSESSIONID) so the two do not conflict.



来源:https://stackoverflow.com/questions/1550111/window-open-clears-session

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!