大雀软件园

首页 软件下载 安卓市场 苹果市场 电脑游戏 安卓游戏 文章资讯 驱动下载
技术开发 网页设计 图形图象 数据库 网络媒体 网络安全 站长CLUB 操作系统 媒体动画 安卓相关
当前位置: 首页 -> 技术开发 -> JSP专区 -> jsp实现cookie的使用

jsp实现cookie的使用

时间: 2021-07-31 作者:daque

package coreservlets; import java.io.*; import javax.servlet.*; import javax.servlet.http.*; /** sets six cookies: three that apply only to the current * session (regardless of how long that session lasts) * and three that persist for an hour (regardless of * whether the browser is restarted). * <p> * taken from core servlets and javaserver pages * from prentice hall and sun microsystems press, * http://www.coreservlets.com/. * © 2000 marty hall; may be freely used or adapted. */ public class setcookies extends httpservlet { public void doget(httpservletrequest request, httpservletresponse response) throws servletexception, ioexception { for(int i=0; i<3; i++) { // default maxage is -1, indicating cookie // applies only to current browsing session. cookie cookie = new cookie("session-cookie-" + i, "cookie-value-s" + i); response.addcookie(cookie); cookie = new cookie("persistent-cookie-" + i, "cookie-value-p" + i); // cookie is valid for an hour, regardless of whether // user quits browser, reboots computer, or whatever. cookie.setmaxage(3600); response.addcookie(cookie); } response.setcontenttype("text/html"); printwriter out = response.getwriter(); string title = "setting cookies"; out.println (servletutilities.headwithtitle(title) + "<body bgcolor=\"#fdf5e6\">\n" + "<h1 align=\"center\">" + title + "</h1>\n" + "there are six cookies associated with this page.\n" + "to see them, visit the\n" + "<a href=\"/servlet/coreservlets.showcookies\">\n" + "<code>showcookies</code> servlet</a>.\n" + "<p>\n" + "three of the cookies are associated only with the\n" + "current session, while three are persistent.\n" + "quit the browser, restart, and return to the\n" + "<code>showcookies</code> servlet to verify that\n" + "the three long-lived ones persist across sessions.\n" + "</body></html>"); } } 

热门阅览

最新排行

Copyright © 2019-2021 大雀软件园(www.daque.cn) All Rights Reserved.