前端设置
$.ajaxSetup( {修改跨域请求携带cookie
xhrFields: {
withCredentials: true
}
} );
后端修改
String origin = request.getHeader("Origin");修改后端请求允许跨域携带cookie
if(origin != null){
response.setHeader("Access-Control-Allow-Origin", origin);
}else{
response.setHeader("Access-Control-Allow-Origin", "*");
}
response.setHeader("Access-Control-Allow-Credentials","true");
转载文章
http://harttle.com/2016/12/28/cors-with-cookie.html#3