☆蓝色梦想☆

世界总是反反覆覆错错落落地飘去 来不及叹息 生活不是平平淡淡从从容容的东西 不能放弃
posts - 57, comments - 5, trackbacks - 0, articles - 0

检查客户端的Cookie设置

Posted on 2005-12-06 10:15 ☆蓝色梦想☆ 阅读(419) 评论(0)  编辑  收藏 所属分类: J2EE

<%@page contentType="text/html; charset=GBK"%><%
//判断客户端是否打开Cook
  if (request.getParameter("flag") == null)
  {
    // the first request
    Cookie cookie = new Cookie("cookieSetting","on");
    response.addCookie(cookie);
    String nextUrl = request.getRequestURI() +"?flag=1";
    // force the browser to refresh
    out.println(nextUrl);
    //out.println("<META HTTP-EQUIV=Refresh CONTENT = 0; URL = " + nextUrl +" > ");
  }
  else
  {
    // the second request
    Cookie[] cookies = request.getCookies();
    boolean cookieFound = false;
    if (cookies != null) {
      int length = cookies.length;
      for (int i = 0; i < length; i++) {
        Cookie cookie = cookies[i];
        if
            (cookie.getName().equals("cookieSetting") &&
             cookie.getValue().equals("on")) {
          cookieFound = true;
          break;
        }
      }
    }
    if (cookieFound) {
      out.println("Cookie is on.");
    }
    else {
      out.println("Cookie is off.");
    }
  }
%>


只有注册用户登录后才能发表评论。


网站导航: