Cookie(String name,String value) 构造器
setValue/getValue 设置值/取出值
setMaxAge/getMaxAge 生命周期
setPath/getPath 生成 cookie 的路径
setDomain/getDomain Cookie 域名设置
生成Cookie:
protectedvoid doGet(HttpservletRequest req, HttpServletResponse resp) throws
ServletException, IOException{
cookiecookie = newcookie("sysId”,System.currentTimeMi11is()+"");
// 设置生命周期为MAX_VALUE
cookte.setMaxAge(Integer.MAX_VALUE);
resp.addcookie(cookie);
}
获取Cookie:
@Override
protected vold doGet(HttpservletRequest req, HttpservletResponse resp) throws ServletException, IOException{
Cookie[] cookies = req.getcookies();
if( null != cookies)(
System.out.printin("cookie信息: ");
for (cookle cookie :cookies){
System.out.print1n( "Name:"+ cookie.getName()
+" , value:"+ cookie.getvalue());