简体   繁体   English

删除Java中的Cookie /浏览器如何删除Cookie

[英]Deleting Cookies in Java / How browser delete cookies

Could someone tell me how to delete the cookie that is either in memory of on hardrive in java on the client side? 有人可以告诉我如何删除客户端Java hardrive内存中的cookie吗? Just like how browser deletes all the cookies and session information. 就像浏览器删除所有cookie和会话信息一样。

I'm trying to do some PoC's for my work and I'm using simple apache Http classes for sending requests and then passing cookies in multiple requests but what if let's say I want to delete my session that is stored in the cookie. 我正在尝试为我的工作做一些PoC,并且正在使用简单的apache Http类发送请求,然后在多个请求中传递cookie,但是如果我想删除存储在cookie中的会话该怎么办。

I think this can be done because all browsers let you do this. 我认为可以做到这一点,因为所有浏览器都可以做到这一点。

Cookies (client side) are the equivalent of sessions (server side). Cookies(客户端)等同于会话(服务器端)。 I don't think there is a way to force the browser to delete the cookie, but you can suggest it to do so by: 我认为没有办法强制浏览器删除cookie,但是您可以建议这样做:

Ending the session on server side: 在服务器端结束会话:

HttpSession session = request.getSession();
session.invalidate();

or setting a short session period of timeout: 或设置较短的会话超时时间:

HttpSession session = request.getSession();
session.setMaxInactiveInterval(1*60); //in seconds

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

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