public static String getCookieValueByName(HttpServletRequest req) {
if(req.getCookies()!=null) {
for(Cookie cookie:req.getCookies()) {
if(cookie.getName().equals("cookieName")) {
try {
return URLDecoder.decode(cookie.getValue(), "UTF-8");//cookie使用utf-8编码
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
return null;
}
}
}
}
return null;
}
if(req.getCookies()!=null) {
for(Cookie cookie:req.getCookies()) {
if(cookie.getName().equals("cookieName")) {
try {
return URLDecoder.decode(cookie.getValue(), "UTF-8");//cookie使用utf-8编码
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
return null;
}
}
}
}
return null;
}