java如何实现cookie的如何使用

相爱的时候,总是会许下郑重的诺言,要一生相守,不离不弃。当那份感觉一旦丢失,过往生死相依的爱恋,竟成了想方设法要擦去的记忆。
packagecoreservlets;importjava.io.*;importjavax.servlet.*;importjavax.servlet.http.*;/**Setssixcookies:threethatapplyonlytothecurrent*session(regardlessofhowlongthatsessionlasts)*andthreethatpersistforanhour(regardlessof*whetherthebrowserisrestarted).*<P>*TakenfromCoreServletsandJavaServerPages*fromPrenticeHallandSunMicrosystemsPress,*http://www.coreservlets.com/.*©2000MartyHall;maybefreelyusedoradapted.*/publicclassSetCookiesextendsHttpServlet{publicvoiddoGet(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{for(inti=0;i<3;i++){//DefaultmaxAgeis-1,indicatingcookie//appliesonlytocurrentbrowsingsession.Cookiecookie=newCookie("Session-Cookie-"+i,"Cookie-Value-S"+i);response.addCookie(cookie);cookie=newCookie("Persistent-Cookie-"+i,"Cookie-Value-P"+i);//Cookieisvalidforanhour,regardlessofwhether//userquitsbrowser,rebootscomputer,orwhatever.cookie.setMaxAge(3600);response.addCookie(cookie);}response.setContentType("text/html");PrintWriterout=response.getWriter();Stringtitle="SettingCookies";out.println(ServletUtilities.headWithTitle(title)+"<BODYBGCOLOR=\"#FDF5E6\">\n"+"<H1ALIGN=\"CENTER\">"+title+"</H1>\n"+"Therearesixcookiesassociatedwiththispage.\n"+"Toseethem,visitthe\n"+"<AHREF=\"/servlet/coreservlets.ShowCookies\">\n"+"<CODE>ShowCookies</CODE>servlet</A>.\n"+"<P>\n"+"Threeofthecookiesareassociatedonlywiththe\n"+"currentsession,whilethreearepersistent.\n"+"Quitthebrowser,restart,andreturntothe\n"+"<CODE>ShowCookies</CODE>servlettoverifythat\n"+"thethreelong-livedonespersistacrosssessions.\n"+"</BODY></HTML>");}}

以上就是javascriptp如何实现cookie的如何使用。愚者用肉体监督心灵,智者专心灵监督肉体。更多关于javascriptp如何实现cookie的如何使用请关注haodaima.com其它相关文章!

标签: java cookie