通过ID在Ajax调用获取会话 [英] Get session by id in ajax call

查看:160
本文介绍了通过ID在Ajax调用获取会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法能够访问会话的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");

这篇关于通过ID在Ajax调用获取会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆