在C:\Documents and Settings\Administrator\Cookies
下面已经存在cookies值NB818906
NB818906
ID=565&TransactorID=2618&Password=123&MinCenterCode=06
10.74.56.2/
9728
4061971712
30110903
2407898208
30110702
*
但我在jsp中通过
  <%  Cookie   allCookie[]   =   request.getCookies();   
Cookie temp = null; if (allCookie!=null)
{
System.out.println("allCookie.length:"+allCookie.length);
for(int   i=0;i<allCookie.length;i++){   
temp = allCookie[i];
System.out.println("allCookie["+i+"].getName():"+allCookie[i].getName());
  if(temp.getName().equals("NB818906"))
{
System.out.println("---"+allCookie[i].getValue());
}
}
}
else
{
System.out.println("null");
} %> 还是取不到NB818906这个键值?急.麻烦看下.谢谢了.

解决方案 »

  1.   

    http://apps.hi.baidu.com/share/detail/275596
    没看出来
    System.out.println("allCookie.length:"+allCookie.length);
    输出来没有?
      

  2.   

    第一次运行cookies.jsp
    输出如下:
    信息: Server startup in 28984 ms
    目标编码:GB2312
    null
    第二次运行cookies.jsp
    输出如下:
    信息: Server startup in 28984 ms
    目标编码:GB2312
    null
    目标编码:GB2312
    allCookie.length:1
    allCookie[0].getName():JSESSIONID
      

  3.   

    我自已在jsp中创建的cookies是可以查看得到的.上面的NB818906这个是人家.net输出的cookies值,放在
    C:\Documents and Settings\Administrator\Cookies
    这个下面,可以看得到.
      

  4.   

    比如:mail.163.com 留下的cookies值也是取不到的,我自已建的cookies值在C:\Documents and Settings\Administrator\Cookies
    下面找不到对应的文件,但我自已建的cookies可以取出来的.
      

  5.   

    删掉cookie。你重新试一下。看了一下。你代码貌似没有问题。。要不你全部打出来看看
      

  6.   

    重新删除cookie 再次运行下  也有可能是IE设置的问题
      

  7.   

    cookies.jsp文件.<%@ page language="java" pageEncoding="ISO-8859-1"%><%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
    <%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
    <%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
    <%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html:html lang="true">
      <head>
        <html:base />
        
        <title>cookie.jsp</title> <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">    
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->  </head>
      
      <body>
      
      <%  Cookie   allCookie[]   =   request.getCookies();   
    Cookie temp = null; if (allCookie!=null)
    {
    System.out.println("allCookie.length:"+allCookie.length);
    for(int   i=0;i<allCookie.length;i++){   
    temp = allCookie[i];
    System.out.println("allCookie["+i+"].getName():"+allCookie[i].getName());
      if(temp.getName().equals("NB818906"))
    {
    System.out.println("---"+allCookie[i].getValue());
    }
    }
    }
    else
    {
    System.out.println("null");
    } %>   </body>
    </html:html>删除IEcookies后,
    c:\Documents and Settings\Administrator\Cookies 下面只剩下index.dat文件.然后,我运行cookies.jsp文件,输出:
    allCookie.length:1
    allCookie[0].getName():JSESSIONID
    我mail.163.com 保存cookies后,再运行cookies.jsp输出同上,没有编化
      

  8.   

    晕,你这里读取的cookies只能读自己的web应用写的cookies,不能跨域!