<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>图片浏览</title>
<script type="text/javascript">
onload=function(){
/*
//1创建/修改cookie
//创建一个有效期为1天的cookie: name="湖南城院"
var d = new Date();
var tm = d.getTime() + 1000*60*60*24; //以毫秒为单位
d.setTime(tm);
var val = "大学湖南";
val = encodeURI(val); //在后台采用 URLDecoder.decode()可以解码出来
//val = escape(val);//对中文要编码处理---这种编码方式是早期版本,本例演示中在后台用 URLDecoder.decode()读不出
document.cookie = "name" + "=" + val + "; expires=" + d.toGMTString()+";path=/";
*/
//2遍历(读取)
var cs = document.cookie.split(";");
for(var i=0; i<cs.length;i++){
myDiv.innerHTML +="<br/>"+cs[i];//显示整个cookie对象
//解析出cookie中的信息(可以处理中文)
cs[i]=decodeURI(cs[i]);
var strs = cs[i].split("=");//strs[0]--key strs[1]--value
myDiv2.innerHTML +="<br/>"+ strs[0]+"="+strs[1];
}
//3删除 (添加一个同名的过期cookie)
var d = new Date(1970,1,1);
var val = "aa";//这个取值无所谓
document.cookie = "name" + "=" + val + "; expires=" + d.toGMTString()+";path=/";
};
</script>
</head>
<body>
<h2>JS操纵cookie技术演示</h2>
<div id="myDiv">
</div>
<div id="myDiv2">
</div>
</body>
</html>