public String[] getUsernameAndTokenFromCookies(HttpServletRequest request){
String[] usernameAndToken = new String[2];
Cookie[] cookies = request.getCookies();
String usernameInCookie = null;
String tokenInCookie = null;
if( cookies != null ){
for (int i = 0; i < cookies.length; i++){
Cookie cookie = cookies[i];
if (cookie.getName().equals("username")){
usernameInCookie = cookie.getValue();
}
if (cookie.getName().equals("token")){
tokenInCookie = cookie.getValue();
}
}
}
usernameAndToken[0] = usernameInCookie;
usernameAndToken[1] = tokenInCookie;
return usernameAndToken;
}
获取cookie里内容
最新推荐文章于 2022-07-14 12:57:15 发布