在ajax调用中通过id获取会话

2023-12-30

有没有办法在对 JAVA 服务器进行 AJAX 调用时访问会话。

在服务器上,request对象同时具有session and cookies特性NULL.

我可以通过会话id作为参数传递,但是如何通过ID访问会话呢?

Edit

Using session.getSession(false);回报null, while session.getSession(true);显然返回一个带有另一个 id 的新会话。


处理此问题的最佳方法是在 url 末尾附加“;jsessionid=”。例如,在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");
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

在ajax调用中通过id获取会话 的相关文章

随机推荐