cookie是保存在本机上的,不同的网站当然能取到了

解决方案 »

  1.   

    public static String getCookie(HttpServletRequest request, String cookieName) {
            Cookie[] cookies = request.getCookies();
            String value = "";        if (cookies != null) {
                for (int i = 0; i < cookies.length; i++) {
                    Cookie cookie = cookies[i];                if (cookieName.equals(cookie.getName())) {
                        value = cookie.getValue();
                    }
                }
            }        return value;
        }
        public static void setCookie(String name, String value,
            HttpServletResponse response, String pathOri) throws WbxException {
            String path = pathOri;
            int cookieAge = 3600 * 24 * 30 * 2;
            Cookie ck = new Cookie(name, value);        if (path == "") {
                path = "/";
            }        ck.setMaxAge(cookieAge);
            ck.setPath(path);
            response.addCookie(ck);
            System.out.println("set cookie:" + name + ";value=" + value);
        }调用:void setSetupCookieFlagforSession(HttpServletRequest request,
            HttpServletResponse response) throws WbxException {
            String cookiename = "CK_BT_SETUP_XXXXX";
            if (!getCookie(request, cookiename).equals("OK")) {
                setCookie(cookiename, "OK", response, "");
    }}
      

  2.   


    调用setDomain方法,设置可以访问cookie的domain。关于cookie的domain在rfc规范里有详细说明。scottwhb的代码根本没有沾边。
      

  3.   

    同意  pigo(少壮且行英雄梦,迟暮归守温柔乡)不同的cookie,虽然是同一个网站,但是它还有域和路径限制的