《JSP完全学习手册》学习心得:cookie读写
<%@page contentType = "text/html;charset=GB2312"%>
<%@page import = "javax.servlet.http.Cookie"%>
<%!int visit ;%>
<%
//读取Cookie
Cookie []cookies = request.getCookies();
for(int i = 0; cookies!=null && i < cookies.length; i++){
Cookie ck = cookies[i];
out.print(ck.getName() + "=" + ck.getValue() + "<br/>");
if(ck.getName().equals("visit"))
visit = Integer.parseInt(ck.getValue());
}
//写入Cookie
visit = visit + 1;
Cookie cookie = new Cookie("visit",""+ visit);
cookie.setMaxAge(60*1);
response.addCookie(cookie);
%>
<%
out.println("第"+visit+"次光临");
%>
原创作品,转载请注明出处。
作者:Winty (wintys@gmail.com)
博客:http://www.blogjava.net/wintys
posted on 2009-05-28 00:03
天堂露珠 阅读(210)
评论(0) 编辑 收藏 所属分类:
JSP