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

入门级问题,大家帮帮忙呀!
这是个设置cookie有效时间的程序,可以运行,但是有一点看不明白就是equlas( "xxx ")这里,大家给解释一下吧!!!
---------------------------login.jsp----------------------------------
<%@   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 "))   ///这里不明白哪来的Name
{
//下面叙述把资料设置给变量
UserName=temp.getValue();  
}
else   if(temp.getName().equals( "E_Mail "))   ///这里不明白哪来的E_Mail
{
//下面叙述把资料设置给变量
UserEMail=temp.getValue();
}
else   if(temp.getName().equals( "LoginDate "))这里不明白哪来的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>
-----------------------settime.jsp----------------------------------
<%@   page   contentType= "text/html;   charset=gb2312 "   language= "java "   import= "java.sql.* "   import= "java.util.Date "   errorPage= " "   %>
<!DOCTYPE   html   PUBLIC   "-//W3C//DTD   XHTML   1.0   Transitional//EN "   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">