1.Cookie 第一次发送请求显示"还没有数据...."
public class CookieDemo extends HttpServlet { @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //创建cookie 对象 Cookie cookie = new Cookie("name", "ckang"); Cookie cookie1 = new Cookie("email","[email protected]"); // 发送cookie到浏览器 response.addCookie(cookie); response.addCookie(cookie1); //获取从浏览器中请求中带来的cookie信息 Cookie[] cookies = request.getCookies(); if (null != cookies) { for(Cookie c : cookies){ String name = c.getName(); String value = c.getValue(); System.out.println(name+":::"+value); } }else{ System.out.println("cookie还没有数据..."); } } }
效果图:
2.Session
时间: 2024-12-20 14:11:42