实例详解JSP内置对象
日期:2008年5月11日 作者: 查看:[大字体 中字体 小字体]-
Cookie DateVal = new Cookie("DateVal", String.valueOf(Now.getTime()));
//欲将储存至Cookie时间/日期值转换为毫秒数
response.addCookie(DateVal); //将Cookie变数加入Cookie中
Cookie temp = null;
DateVal = null; //重设Cookie变数
Cookie[] cookies = request.getCookies();
//取得Cookie资料
int cookielen = cookies.length;
//取得Cookie变数阵列的长度
if(cookielen != 0) //判断是否成功取得Cookie资料
{
for (int i = 0; i < cookielen; i++)
{
temp = cookies[i]; //取得cookies阵列中的Cookie变数
if (temp.getName().equals("DateVal"))
{ //判断是否取得名为DateVal的Cookie资料
%>
Cookie中<Font color = blue>DateVal</Font>
变量的值为<Font color = red>
<%= new Date(Long.parseLong(temp.getValue())) %>
</Font><BR>
<%
}
}
}
else //若无法取得Cookie资料则执行下面的叙述
{
%>
无法取得Cookie<BR>
<%
}
%>
</BODY>
</HTML>
(出处:急速软件下载学院)
下一篇:JSP连接sybase数据库中文显示问题终极解决办法
