动网论坛,站长建站首选,国内使用量最多的论坛软件 动网论坛官方技术讨论区 站长工具 申请属于您自己的免费论坛
首页 | 新闻资讯 | 网站运营 | 网络编程 | 数据库 | 服务器 | 网页设计 | 图像媒体 | 网络应用 | 搜索优化 | 资源下载 | 动网主机 | DVBOX
    本站内  互联网 ASP论坛  ASP.Net论坛  PHP论坛
  
   Asp → 阅读文章

 jsp源码实例5(cookie)

作者来源: 
阅读 数 624 人次 , 2006-3-29 4:22:00 



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/.
* &copy; 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>");
}
}

 本文Tagscookies  
 收藏本文  打印本文  论坛讨论  关闭窗口
· 上一篇:邮件发送简单例子-bean文件
· 下一篇:jsp源码实例4(搜索引擎)
· 一个用c#写的扫描asp源码漏洞的应用程序(续)
· 用文本+ASP打造新闻发布系统/图片上传
· 使用ASP生成图片彩色校验码
· ASP+全新接触(3)
· 应用程序设计范例的研究


关于本站 | 联系我们 | 业务合作 | 客户案例 | 诚聘英才 | 广告合作 | 收藏本站
海口动网先锋网络科技有限公司版权所有
Copyright © 2000 - 2006 Cndw.Com
中华人民共和国电信与信息服务业务经营许可证编号 琼 ICP 020077