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

关于cookie,大家给看看吧,谢谢!
<%@   page   contentType= "text/html;   charset=gb2312 "   language= "java "   import= "java.sql.* "   errorPage= " "   %>
<!DOCTYPE   html   PUBLIC   "-//W3C//DTD   XHTML   1.0   Transitional//EN "   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">

<%
//起始变量
String   UserName= " ",UserEMail= " ",LoginDate= " ";
Cookie   temp=null;

//取得Cookie变量数组
Cookie[]   cookies=request.getCookies();

//取得Cookie变量数组的长度
int   cookielen=cookies.length;

//利用for循环从Cookie中取得资料
for(int   i=0;i <cookielen;i++)
{
temp=cookies[i];

//判断是否可取得Cookie中的资料
if(temp.getName().equals( "Name "))
{
//下面叙述把资料设置给变量
UserName=temp.getValue();
}
else   if(temp.getName().equals( "E_Mail "))
{
//下面叙述把资料设置给变量
UserEMail=temp.getValue();
}
else   if(temp.getName().equals( "LoginDate "))
{
//下面叙述把资料设置给变量
LoginDate=temp.getValue();
}
}

int   tmplen=LoginDate.length();
boolean   FirstLogin;
if(tmplen!=0)
{
//设置不是第一次登录
FirstLogin=false;
}
else
{
//预设为true,代表第一次浏览网页
FirstLogin=true;
}
%>

<html   xmlns= "http://www.w3.org/1999/xhtml ">
<head>
<meta   http-equiv= "Content-Type "   content= "text/html;   charset=gb2312 "   />
<title> Cookie有效时间的设置 </title>
</head>
<body>
<center>
    <font   size=5   color=blue> Cookie有效时间的设置 </font>
</center>
<hr>
<br>
<%
//若FirstLogin为true,表示第一次浏览此网页
if(FirstLogin==true)
{//下面是第一次浏览所显示的欢迎词
%>
首度光临的朋友,欢迎你们!请输入您的姓名与E_Mail登录
<%
}
else  
{
//下面是非第一次浏览时所显示的欢迎词
%>
欢迎再度光临,您曾于   <font   size=4   color=red> <%=LoginDate%> </font> 访问过本站!
<%
}
%>
<form   action= "settime.jsp "   method= "Post "   name= "form ">
    <P> 姓名:
        <input   name= "tmpName "   value= " <%=UserName%> ">
    </p>
    <P> E_Mail:
        <input   name= "tmpE_Mail "   value= " <%=UserEMail%> ">
    </p>
    <input   name= "submit1 "   type= "submit "   value= "登录 ">
</form>
</body>
</html>

其中这里的Name是什么?
if(temp.getName().equals( "Name "))



------解决方案--------------------
关键字 key
------解决方案--------------------
类似于hashtable里的设置,Hashtable hs=new Hashtable();
hs.put(key,value);
通过key可以取得key对应的value