在java中添加cookie然后HTTP重定向不会在客户端显示cookie
我有一个要求,我需要在java中添加cookie,然后将其重定向到不同的URL。现在这个 url 进程应该保留我设置的 cookie,并在处理后将其发送回客户端。代码如下,
Cookie cookie = new Cookie("name", "value")
// To make sure cookie is established for all the url paths
cookie.setPath(request.getContextPath());
response.addCookie(cookie);
response.sendRedirect("someNewUrl");
请帮助我了解如何在整个重定向生命周期和客户端中保留 cookie。提前致谢。
I have requirement where in i need to add cookie in java and then redirect it to different URL. Now this url process should persist the cookie which i set and after its processing send it back to client. The code goes as follows
Cookie cookie = new Cookie("name", "value")
// To make sure cookie is established for all the url paths
cookie.setPath(request.getContextPath());
response.addCookie(cookie);
response.sendRedirect("someNewUrl");
Please help me regarding how can i persist the cookie throughout the redirect lifecycle and to the client. Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试将 cookie 添加到响应中:
另请参阅:
Try to actually add the cookie to the response:
See also:
您是否将 cookie 添加到响应中?
我看到了刚刚创建 cookie 的代码。
试试这个:
Did you add the cookie to the response?
I'm seeing the code that just creates the cookie.
Try this :