佳木斯湛栽影视文化发展公司

主頁 > 知識(shí)庫 > jsp實(shí)現(xiàn)cookie的使用

jsp實(shí)現(xiàn)cookie的使用

熱門標(biāo)簽:阿里云 銀行業(yè)務(wù) 團(tuán)購網(wǎng)站 Linux服務(wù)器 電子圍欄 Mysql連接數(shù)設(shè)置 服務(wù)器配置 科大訊飛語音識(shí)別系統(tǒng)

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存儲(chǔ)中文示例分享
  • 用JSP操作Cookie
  • JSP實(shí)現(xiàn)瀏覽器關(guān)閉cookies情況下的會(huì)話管理
  • jsp源碼實(shí)例5(cookie)
  • JSP的Cookie在登錄中的使用

標(biāo)簽:衢州 江蘇 廣元 衡水 萍鄉(xiāng) 蚌埠 棗莊 大理

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《jsp實(shí)現(xiàn)cookie的使用》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266
    阳城县| 酉阳| 抚松县| 阿合奇县| 南京市| 特克斯县| 诸暨市| 宁阳县| 阜新| 屯门区| 烟台市| 闵行区| 平定县| 开江县| 河南省| 阿荣旗| 永福县| 同德县| 遂昌县| 新泰市| 镇原县| 安徽省| 宁乡县| 齐齐哈尔市| 辽宁省| 新竹县| 林西县| 泾川县| 云林县| 朔州市| 苏尼特右旗| 河间市| 巴楚县| 靖边县| 阆中市| 温宿县| 五常市| 南部县| 青州市| 丹棱县| 台安县|