js读取cookie测试

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns=
"http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv=
"Content-Type" content="text/html; charset=utf-8" />
<title>js读取cookie测试</title>
<link href=
"css/08nzfh-style.css" rel="stylesheet" type="text/css" />
<style type=
"text/css">
<!--
.STYLE1 {color: #FF0000}
-->
</style>
</head>

<body>

<div class=
"personality">
<script type=
"text/javascript">
//<![CDATA[
function   setCookie(name,value)
{
    var   Days   =   30;  
//此   cookie   将被保存   30   天
    var   exp     =   new   Date();        
//new   Date( "December   31,   9998 ");
    exp.setTime(exp.getTime()   +   Days*24*60*60*1000);
    document.cookie   =   name   +  
"= "+   escape(value)   + ";expires= "+   exp.toGMTString();
}

function getCookie2(objName){
//获取指定名称的cookie的值
   var arrStr = document.cookie.split(
"; ");
   for(var i = 0;i < arrStr.length;i ++){
    var temp = arrStr<i>.split(
"=");
    if(temp[0] == objName) return unescape(temp[1]);
   }
}

var _b = false;
//setCookie("mycookie","mycookie");
if(typeof(getCookie2(
"mycookie2"))   !=   'undefined')  
{  
   alert(typeof(getCookie2(
"mycookie2")));
   _b = true;
}
alert(_b);
if(_b){
document.write('<iframe id=
"iframe_email" name="iframe_email" frameborder="0" scrolling="no" src="http://localhost:8008/vote1.4/test_8.jsp" height="100%" width="100%"></iframe>');
}else{
document.write('<iframe src=
"#" style="display:none;"></iframe> 请登录');
}
//]]>
</script>

</body>
</html>
参考资料:http:
//www.xrss.cn/Dev/Other/2007111617660.Html
下边这个是jsp读取cookie的方法
<html>
<head>
<title>使用Cookie对象的方法 </title>
</head>
<%@ page contentType=
"text/html;charset=utf-8" %>
<body>
<%
  Cookie myCookie = new Cookie(
"mycookie2", "myvalue2");
   response.addCookie(myCookie);
  
//得到所有的Cookie
   Cookie[] coos=request.getCookies();
  
//将计数值初始化
   for(int i=0;i<coos.length;i++)
   {
Cookie coo=coos<i>;
//找到name值为"jsp"的Cookie
if(coo.getName().equals(
"mycookie2"))
{
      out.println(coo.getValue());
break;
}
   }
  
  
%>

</body>
</html>

lunzi   2008-06-13 23:07:45 评论:0   阅读:3445   引用:0

发表评论>>

署名发表(评论可管理,不必输入下面的姓名)

姓名:

主题:

内容: 最少15个,最长1000个字符

验证码: (如不清楚,请刷新)

Copyright@2008 powered by YuLog