Article Directory
Problem scenario
When testing the exit function of the project, it was found that after exiting, the microservice framework generated cookie
still exists. When entering the homepage, there is no abnormal jump, but normal entry. For simple handling, the use of native JS
be cookie
deleted. But after execution, it was cookie
not deleted normally and cookie
still exists. This blog is mainly about the reasons and solutions for this situation.
Problem environment
software | version |
---|---|
JDK | 8 |
problem causes
Open the devtools page of Google Chrome, check the cookie
page, you can find that there is an attribute inside HttpOnly
, this attribute is mainly to make the js
relevant information in the webpage code unable to obtain, but the server can obtain it normally. The property to be deleted cookie
is set HTTPONLY
, so it cannot be controlled and cleared by JS. As shown below:
solution
Now that the server can operate normally, a clear cookie
interface is developed on the server , and then the interface is called to delete. The delete code is as follows:
public static void removeCookie(HttpServletResponse response, String name) {
Cookie uid = new Cookie(name, null);
uid.setPath("/");
uid.setMaxAge(0);
uid.setHttpOnly(true);
response.addCookie(uid);
}
result
After calling the interface, it will cookie
be deleted smoothly .
to sum up
Pits are everywhere, you need to study and think more! ! !
Ask for praise
If my article is helpful to everyone, you can click like or favorite at the bottom of the article;
if there is a good discussion, you can leave a message;
if you want to continue to view my future articles, you can click Follow
You can scan the following QR code to follow me 'S public account: Fengye Zhixuege, check out my latest share!