主頁 > 知識庫 > jsp源碼實例5(cookie)

jsp源碼實例5(cookie)

熱門標簽:長春回撥外呼系統(tǒng)廠家 電銷外呼系統(tǒng) 排行榜 地圖標注制作道路 四川電信外呼系統(tǒng)靠譜嗎 山東智能云外呼管理系統(tǒng) 外呼系統(tǒng)啥意思 廣州三五防封電銷卡 珠海銷售外呼系統(tǒng)運營商 地圖標注創(chuàng)業(yè)項目入駐
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; i3; 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>");
}
}
您可能感興趣的文章:
  • 關(guān)于jsp中cookie丟失問題(詳解)
  • jsp使用cookie存儲中文示例分享
  • jsp實現(xiàn)cookie的使用
  • 用JSP操作Cookie
  • JSP實現(xiàn)瀏覽器關(guān)閉cookies情況下的會話管理
  • JSP的Cookie在登錄中的使用

標簽:玉樹 北海 保定 肇慶 紹興 廣元 吳忠 潮州

巨人網(wǎng)絡(luò)通訊聲明:本文標題《jsp源碼實例5(cookie)》,本文關(guān)鍵詞  jsp,源碼,實例,cookie,jsp,源碼,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《jsp源碼實例5(cookie)》相關(guān)的同類信息!
  • 本頁收集關(guān)于jsp源碼實例5(cookie)的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章