简体   繁体   English

JavaScript中的JSESSIONID-Open Layers 3如何获取它?

[英]JSESSIONID in javascript - How can Open Layers 3 obtain it?

I have created an Open Layers 3 Map which loads its tiles from my server, i dont transmit the user id, it's recognized server side, so the map does not work if there is not user logged in. 我创建了一个Open Layers 3 Map,可以从我的服务器上加载其图块,我不传输用户ID,它是服务器端,因此如果没有用户登录,该地图将无法正常工作。

So far so good, everything working. 到目前为止,一切正常。 If someone clicks on a feature in the map i would like to send some request to the server as well, also without sending the user id, cause there should be a session anyway. 如果有人单击地图上的某个功能,我也想向服务器发送一些请求,同时也没有发送用户ID,那么无论如何应该有一个会话。 But if i send an AJAX request to the server, then the JSESSIONID will be missing from the request and i get a new session id every time i send a request. 但是,如果我向服务器发送AJAX请求,则请求中将缺少JSESSIONID,并且每次发送请求时都会获得一个新的会话ID。

I know this is due to HttpOnly flag, but what bugs me is, how can Open Layers have the JSESSIONID in its requests, but i dont get it for my own Ajax requests. 我知道这是由于HttpOnly标志引起的,但令我感到烦恼的是,开放层如何在其请求中包含JSESSIONID,但我自己的Ajax请求却没有得到它。

See also the picture for the difference: 另请参见图片以了解区别:

-- GetTile is a request generated by Open Layers -GetTile是由Open Layers生成的请求

-- GetStarMapData is a request generated by own written Ajax call -GetStarMapData是由自己的书面Ajax调用生成的请求

Both requests just access a servlet on the Server 这两个请求都只访问服务器上的一个servlet。

在此处输入图片说明

Cross-origin XHR requests (the Origin in your screenshot indicates you are making one) only include cookies if you explicitly turn credentials support on. 跨域XHR请求(屏幕快照中的Origin表示您正在发出请求)仅在您明确启用凭据支持时才包含cookie。

xhr.withCredentials = true;

This will make it a preflighted request so you will have to configure the server to correctly respond to OPTIONS. 这将使其成为一个预先处理的请求,因此您将必须配置服务器以正确响应OPTIONS。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM