从HttpServletRequest获取Cookie
import java.io.UnsupportedEncodingException; import java.text.SimpleDateFormat;//来自 nowjava - 时代Java import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class Main{ /** * Method getCookie. * * @param request * @param cookieName * @return String * @throws Exception */ public static String getCookie(HttpServletRequest request, String cookieName) { Cookie[] cookies = request.getCookies(); if (cookies == null) { return ""; } String value = ""; for (int i = 0; i < cookies.length; i++) { if (cookieName.equals(cookies[i].getName())) {/** from NowJava.com - 时代Java**/ try { value = java.net.URLDecoder.decode( cookies[i].getValue(), "utf-8"); }