有没有一种方法能够访问会话的AJAX调用Java服务器进行。
Is there a way to have access to session in a AJAX call made to a JAVA server.
在服务器上,要求
对象的会话
和饼干属性
NULL
。
On the server, the request
object has both the session
and cookies
properties NULL
.
我可以通过,虽然该会话ID作为参数,但如何通过ID访问会话?
I can pass though the session id as a parameter, but how can I access the session by ID?
修改
使用 session.getSession(假);
返回空
,而 session.getSession (真);
显然会返回一个新的会话,与另一个ID
Using session.getSession(false);
returns null
, while session.getSession(true);
obviously returns a new session, with another id.
最好的解决方法是追加的方式; JSESSIONID =在URL的末尾。例如,在一个jsp:
The best way to deal with this is to append ";jsessionid=" at the end of the url. For instance, in a jsp:
<script type="text/javascript">
...
xhr.open("GET", url + ";jsessionid=<%=pageContext.getSession().getId()%>");
...
</script>
该行:
xhr.open("GET", url + ";jsessionid=<%=pageContext.getSession().getId()%>");
将呈现为:
xhr.open("GET", url + ";jsessionid=6EBA4F94838796DC6D653DCA1DD06373");