前端开发使用的VUE,后端使用的java,前后端分离,因为跨域问题JSESSIONID每次请求都会变化,解决方法如下:
前端要将withCredentials设为true
以ajax请求为例:
$.ajax({
url: a_cross_domain_url,
// 将XHR对象的withCredentials设为true
xhrFields: {
withCredentials: true
}
});
httpResponse.setHeader("Access-Control-Allow-Credentials", "true");
httpResponse.setHeader("Access-Control-Allow-Origin", "http://192.168.199.240:8081");
httpResponse.setHeader("Access-Control-Allow-Headers", "Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");
Access-Control-Allow-Credentials 设为true的话,Access-Control-Allow-Origin就不能设为*了,只好改成具体的域了,这样就可以多次请求取到的sessionid就一致了。
版权声明:本文为huang369509940原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。