// 模拟Cookie
Cookie cookie1 = new Cookie("num", "001");
Cookie cookie2 = new Cookie("name", URLEncoder.encode("张三", "UTF-8"));
response.addCookie(cookie1);
response.addCookie(cookie2);
// 获取Cookie
Cookie[] cookies = request.getCookies();
String cookieNum = "";
String cookieName = "";
for (Cookie cookie : cookies)
{
if ("num".equals(cookie.getName()))
{
cookieNum = cookie.getValue();
}
else if ("name".equals(cookie.getName()))
{
cookieName = URLDecoder.decode(cookie.getValue(), "UTF-8");
}
}
转载于:https://blog.51cto.com/woshixy/1352953