try {
CookieManager manager = new CookieManager();
CookieHandler.setDefault(manager);
CookieStore cookieJar = manager.getCookieStore();
HttpCookie cookie = new HttpCookie("user", username);
URL url = new URL("http://host.example.com");
cookieJar.add(url.toURI(), cookie);
System.out.println("Added cookie using cookie handler");
} catch(Exception e) {
System.out.println("Unable to set cookie using CookieHandler");
e.printStackTrace();
}
如何为cookie过期添加时间,因为现在它更像是一个会话cookie。每次销毁/关闭应用程序时它都会过期