//把数据存储到cookie中。
public class SetCookie_01 extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
//创建Cookie对象
Cookie cookie = new Cookie("userName","gouwa");
//设置cookie最大有效时间
cookie.setMaxAge(60*60*24*7);
//设置有效路径
cookie.setPath("/day39/getCookie");
//把cookie 发送给浏览器
response.addCookie(cookie);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
}
把数据存在cookie
猜你喜欢
转载自blog.csdn.net/chenzuen113113/article/details/80919187
今日推荐
周排行