日期:2014-05-18  浏览次数:20662 次

有关JSP中Cookie的问题
我向客户端添加了Cookie
Cookie   cookie=new   Cookie( "cookie_name ", "cookie_value ");
response.addCookie(cookie);

Cookie[]   cs=request.getCookie();
for(int   i=0;i <cs.length;i++)
{
        out.println( "cookie_name= "+cs[i].getName()+ "cookie_value= "+cs[i].getValue())
}
在读取的时候却得到cookie_name=JSESSIONID   cookie_value=XXXXXXXXXX(很长)
望高手指点

------解决方案--------------------
<HTML>

<HEAD>



<TITLE>

Jsp2

</TITLE>

</HEAD>

<BODY>

<%

Cookie ck = new Cookie( "cww2 ", "test2!! ");

ck.setMaxAge(65536);

response.addCookie(ck);

%>

</BODY>

</HTML>



GetCookie 之範例

<HTML>

<HEAD>

<TITLE>

getcookie

</TITLE>

</HEAD>

<BODY>

<H1>

JBuilder Generated JSP

</H1>

<%

Cookie ck[] = request.getCookies();

int i;

for(i=0;i <ck.length;i++) {

out.print( "ck.name= "+ck[i].getName());

out.print( " value= " + ck[i].getValue()+ " <BR> ");

}



%>

ok

</BODY>
------解决方案--------------------
request.getCookies少加了个s