有哪位老兄知道怎样用jsp实现cookie跨多域访问?(100分) cookie是保存在本机上的,不同的网站当然能取到了 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 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, "");}} 调用setDomain方法,设置可以访问cookie的domain。关于cookie的domain在rfc规范里有详细说明。scottwhb的代码根本没有沾边。 同意 pigo(少壮且行英雄梦,迟暮归守温柔乡)不同的cookie,虽然是同一个网站,但是它还有域和路径限制的 关于用StandardAnalyzer分词的问题 简单的java实体类中的构造器问题 Tomcat的不同版本对相对路径的处理不同么? sesson.getAttribute()返回值转换类型 jsp页面输入中文搜索问题~与sql数据库有关~!请教~~~~ 向各位前辈请教一下SSH的学习方法 100求助servlet 一个struts连接oracle的问题 简单问题!!!送分!!! 关于执行执行Update以及delete操作的问题 jsp如何取得实际ip地址(急) java如何解析html文档呢
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, "");
}}
调用setDomain方法,设置可以访问cookie的domain。关于cookie的domain在rfc规范里有详细说明。scottwhb的代码根本没有沾边。