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;
}
更新于 阅读次数

请我喝[茶]~( ̄▽ ̄)~*

Jalen Chu 微信支付

微信支付

Jalen Chu 支付宝

支付宝

Jalen Chu 公众号

公众号