我在服务中使用了此代码,以便添加cookie以重新放置:
private void addCookies(HttpServletResponse response) {
response.addCookie(new Cookie(TOKEN_COOKIE_NAME, this.obtainToken()));
}
有两个添加cookie的端点:
_/startby
_/descarregaby/{id}
这是每个代码:
@RequestMapping(
value = "/startby",
method = RequestMethod.GET
)
public void getTokenAfterGicar(
HttpServletRequest request,
HttpServletResponse response
) throws IOException {
this.addCoockie(response);
/* Other code */
}
@RequestMapping(
value = "/descarregaby/{id}",
method = RequestMethod.GET
)
@Override
public void downloadAfterGicar(
HttpServletRequest request,
HttpServletResponse response,
@PathVariable("id") String id
) throws IOException {
this.addCoockie(response);
/* Other code */
}
此代码运行良好。不过:
_/startby
时,库克存储在/
路径上。_/descarregaby/anyid
时,cookie存储在/descarregaby
路径上。请参阅:
我需要更改此行为,以将descarregaby/{id}
cookie存储在/
路径上。
我的角度代码是:
sessionStorage.setItem('coockie-key', value);
有什么想法吗?