馬光軍--------BLOG

          BlogJava 聯系 聚合 管理
            1 Posts :: 25 Stories :: 5 Comments :: 0 Trackbacks
          <%@ page language="java" pageEncoding="utf-8"%>
          <html>
              
          <head>
                  
          <title>My JSP 'MyJsp.jsp' starting page</title>
              
          </head>
              
          <body bgcolor="#FFFFFF">
                  
          <%
                      
          int counter = 0;
                      
          //得到所有的Cookie
                      
          //與其它內置對象不同,Cookie首字母大寫
                      Cookie cookies[] 
          = request.getCookies();
                      
          //request對象獲取Cookie
                      
          if (cookies != null) {
                          
          for (int i = 0; i < cookies.length; i++) {
                              
          if (cookies[i].getName().equals("counter")){
                                  counter 
          = Integer.parseInt(cookies[i].getValue()) + 1;
                                  System.out.println(cookies[i].getName());
                                  out.println(cookies[i].getName());
                              }
                          }
                      }
                      
          // 首次登陸,需要創建Cookie;以后登陸,需更新Cookie
                      Cookie c 
          = new Cookie("counter""" + counter);
                      c.setMaxAge(
          60 * 60 * 24 * 365); //設置Cookie有效期
                      response.addCookie(c);
                      
          //response對象添加Cookie
                      
          if (counter == 0){
                          out.println(
          "First!Welcome!");
                      }
          else{
                          out.println(counter 
          + " times!");
                      }
                  
          %>
              
          </body>
          </html>
          posted on 2008-12-02 20:38 馬光軍 閱讀(69) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 太谷县| 郧西县| 宁德市| 蒲城县| 思南县| 平乡县| 巴彦县| 鹰潭市| 双城市| 洛浦县| 敦煌市| 尼木县| 茌平县| 融水| 汝南县| 平泉县| 合山市| 闽清县| 平塘县| 铁岭县| 儋州市| 松桃| 梅河口市| 永胜县| 清徐县| 德州市| 昆明市| 金塔县| 尖扎县| 宁武县| 涿鹿县| 江华| 永登县| 弥勒县| 柞水县| 红原县| 宜阳县| 巴林右旗| 麻栗坡县| 钟山县| 得荣县|