刚在csdn上回答了一个这样的问题:
在ASP中,对COOKIE的读写用如下代码:
发送:response.Cookies("useruv")("num") =numA
接收:numB = request.Cookies("useruv")("num")
现 在由于编程需要,写入COOKIE的时候只能在javascript中写入,但javascript不支持response.Cookies ("useruv")("num") =numA 这样的写入方式,好像javascript只支持document.cookie=numA 这样的写入方式,可这句 document.cookie=numA 代码没能考虑到useruv 。
现要做的是在javacript中编写一段代码来代替
response.Cookies("useruv")("num") =numA
使之和原来的那一句功能一样,而读出cookie的时候依然采用原来的接收方式:
接收:numB = request.Cookies("useruv")("num")
请大侠们帮帮小弟把这一段代写出来,高分重谢!!!
在线等!!!!!!!!!!!!!!!!!
http://community.csdn.net/Expert/TopicView3.asp?id=5727826
在网上找了很多,没有关系cookies字典的清楚说明,也没有关于普通cookie和cookie字典 存在硬盘cookie文件夹上的格式 (cookie文件夹 :C:/Documents and Settings/Administrator.ZOURINET/Cookies)一般是这个,我的是window2003serversp1
事实是这样子的
普通cookie存储格式:
cccc
aaaadddddddddddddddddd
172.18.14.84/erp
1536
1313521664
30050866
2706658688
29877947
*
bbbb
aaaadddddddddddddddddd
172.18.14.84/erp
1536
1313521664
30050866
2706658688
29877947
*
aaaa
aaaadddddddddddddddddd
172.18.14.84/erp
1536
1313521664
30050866
3420558688
29877947
*
上面表示 cccc的值等于aaaadddddddddddddddddd,bbbb的值等于aaaadddddddddddddddddd,.........
而cookie字典存储格式:
person2
age=223333&id=zourinet2
172.18.14.84/erp
1536
1313521664
30050866
3420558688
29877947
*
person1
age=22&id=zourinet
172.18.14.84/erp
1536
1313521664
30050866
2046808688
29877947
*
表示person2里面age的值是22333,id为zourinet2,person1里面的age为22,id为zourinet
字典存储的格式为表格,二维数组,
js对cookies字典的操作如下
<%@ LANGUAGE="VBSCRIPT" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> New Document </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="zourinet">
<meta name="Keywords" content="">
<meta name="Description" content="">
</head>
<body>
<script language="JavaScript">
<!--
function SetCookie(name,value){
expires=new Date();
expires.setTime(expires.getTime()+(86400*365));
document.cookie=name+"="+value+"; expires="+expires.toGMTString()+"; path=/";
}
function getCookie(Name) {
var search = Name + "="
if (document.cookie.length > 0) { // if there are any cookies
offset = document.cookie.indexOf(search)
if (offset != -1) { // if cookie exists
offset += search.length
end = document.cookie.indexOf(";", offset)
if (end == -1)
end = document.cookie.length
return unescape(document.cookie.substring(offset, end))
}
}
return 0;
}
SetCookie("person","id=zourinet&age=22");
document.write(getCookie("person"));
//-->
</script>
<%
Response.Write Request.Cookies ("person")("id")
%>
</body>
</html>
上面SetCookie("person","id=zourinet&age=22");设置了person的两个属性(这里我们对象的眼光来看)
上面就成功的将person对象写入了cookie,person 就是一个cookie字典了
js读取:document.write(getCookie("person"));
asp读取<%
Response.Write Request.Cookies ("person")("id")
%>
这样就可取得:person的属性id了
[注]由于上面asp代码是服务器代码需要多刷新一次(明白吧)要等js写入后方能读到
另外发现这种方法也可以写入(不过有一个缺点)如下
<%@ LANGUAGE="VBSCRIPT" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> New Document </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="zourinet">
<meta name="Keywords" content="">
<meta name="Description" content="">
</head>
<body>
<script language="JavaScript">
<!--
function SetCookie(name,value){
expires=new Date();
expires.setTime(expires.getTime()+(86400*365));
//document.cookie=name+"="+value+"; expires="+expires.toGMTString()+"; path=/";
document.cookie="person="+name+"="+value+"; expires="+expires.toGMTString()+"; path=/";
}
function getCookie(Name) {
var search = Name + "="
if (document.cookie.length > 0) { // if there are any cookies
offset = document.cookie.indexOf(search)
if (offset != -1) { // if cookie exists
offset += search.length
end = document.cookie.indexOf(";", offset)
if (end == -1)
end = document.cookie.length
return unescape(document.cookie.substring(offset, end))
}
}
return 0;
}
SetCookie("id","zourinet");
SetCookie("age","22");
//document.write(getCookie("person"));
//-->
</script>
<%
Response.Write Request.Cookies ("person")("age")
%>
</body>
</html>
用黄色标注不同点,就是直接在写cookie时将类名写入
缺点就是设置属性的时候只能写入一个,后一个会将前一个覆盖.
还有只有设置了cookie的过期时间,才能在cookie文件夹中找到.[记的]
差不多了
主 题: | 高分求教一个简单的问题,在线等!!! | |
作 者: | pcegp36 () | |
等 级: | ||
信 誉 值: | 100 | |
所属论坛: | Web 开发 JavaScript | |
问题点数: | 100 | |
回复次数: | 8 | |
发表时间: | 2007-8-25 7:38:13 | |
发送:response.Cookies("useruv")("num") =numA
接收:numB = request.Cookies("useruv")("num")
现 在由于编程需要,写入COOKIE的时候只能在javascript中写入,但javascript不支持response.Cookies ("useruv")("num") =numA 这样的写入方式,好像javascript只支持document.cookie=numA 这样的写入方式,可这句 document.cookie=numA 代码没能考虑到useruv 。
现要做的是在javacript中编写一段代码来代替
response.Cookies("useruv")("num") =numA
使之和原来的那一句功能一样,而读出cookie的时候依然采用原来的接收方式:
接收:numB = request.Cookies("useruv")("num")
请大侠们帮帮小弟把这一段代写出来,高分重谢!!!
在线等!!!!!!!!!!!!!!!!!
http://community.csdn.net/Expert/TopicView3.asp?id=5727826
在网上找了很多,没有关系cookies字典的清楚说明,也没有关于普通cookie和cookie字典 存在硬盘cookie文件夹上的格式 (cookie文件夹 :C:/Documents and Settings/Administrator.ZOURINET/Cookies)一般是这个,我的是window2003serversp1
事实是这样子的
普通cookie存储格式:
cccc
aaaadddddddddddddddddd
172.18.14.84/erp
1536
1313521664
30050866
2706658688
29877947
*
bbbb
aaaadddddddddddddddddd
172.18.14.84/erp
1536
1313521664
30050866
2706658688
29877947
*
aaaa
aaaadddddddddddddddddd
172.18.14.84/erp
1536
1313521664
30050866
3420558688
29877947
*
上面表示 cccc的值等于aaaadddddddddddddddddd,bbbb的值等于aaaadddddddddddddddddd,.........
而cookie字典存储格式:
person2
age=223333&id=zourinet2
172.18.14.84/erp
1536
1313521664
30050866
3420558688
29877947
*
person1
age=22&id=zourinet
172.18.14.84/erp
1536
1313521664
30050866
2046808688
29877947
*
表示person2里面age的值是22333,id为zourinet2,person1里面的age为22,id为zourinet
字典存储的格式为表格,二维数组,
js对cookies字典的操作如下
<%@ LANGUAGE="VBSCRIPT" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> New Document </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="zourinet">
<meta name="Keywords" content="">
<meta name="Description" content="">
</head>
<body>
<script language="JavaScript">
<!--
function SetCookie(name,value){
expires=new Date();
expires.setTime(expires.getTime()+(86400*365));
document.cookie=name+"="+value+"; expires="+expires.toGMTString()+"; path=/";
}
function getCookie(Name) {
var search = Name + "="
if (document.cookie.length > 0) { // if there are any cookies
offset = document.cookie.indexOf(search)
if (offset != -1) { // if cookie exists
offset += search.length
end = document.cookie.indexOf(";", offset)
if (end == -1)
end = document.cookie.length
return unescape(document.cookie.substring(offset, end))
}
}
return 0;
}
SetCookie("person","id=zourinet&age=22");
document.write(getCookie("person"));
//-->
</script>
<%
Response.Write Request.Cookies ("person")("id")
%>
</body>
</html>
上面SetCookie("person","id=zourinet&age=22");设置了person的两个属性(这里我们对象的眼光来看)
上面就成功的将person对象写入了cookie,person 就是一个cookie字典了
js读取:document.write(getCookie("person"));
asp读取<%
Response.Write Request.Cookies ("person")("id")
%>
这样就可取得:person的属性id了
[注]由于上面asp代码是服务器代码需要多刷新一次(明白吧)要等js写入后方能读到
另外发现这种方法也可以写入(不过有一个缺点)如下
<%@ LANGUAGE="VBSCRIPT" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> New Document </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="zourinet">
<meta name="Keywords" content="">
<meta name="Description" content="">
</head>
<body>
<script language="JavaScript">
<!--
function SetCookie(name,value){
expires=new Date();
expires.setTime(expires.getTime()+(86400*365));
//document.cookie=name+"="+value+"; expires="+expires.toGMTString()+"; path=/";
document.cookie="person="+name+"="+value+"; expires="+expires.toGMTString()+"; path=/";
}
function getCookie(Name) {
var search = Name + "="
if (document.cookie.length > 0) { // if there are any cookies
offset = document.cookie.indexOf(search)
if (offset != -1) { // if cookie exists
offset += search.length
end = document.cookie.indexOf(";", offset)
if (end == -1)
end = document.cookie.length
return unescape(document.cookie.substring(offset, end))
}
}
return 0;
}
SetCookie("id","zourinet");
SetCookie("age","22");
//document.write(getCookie("person"));
//-->
</script>
<%
Response.Write Request.Cookies ("person")("age")
%>
</body>
</html>
用黄色标注不同点,就是直接在写cookie时将类名写入
缺点就是设置属性的时候只能写入一个,后一个会将前一个覆盖.
还有只有设置了cookie的过期时间,才能在cookie文件夹中找到.[记的]
差不多了