writeCookie.jsp:
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
http://www.w3.org/1999/xhtml">
writeCookie
<%
String username="prometheus";
String cookieName="cookie_Name";
Cookie cookie=new Cookie(cookieName, "cookie_Content");
/*第一个参数cookieName定义了Cookie的名字,后一个参数,也是个字符串,定义了Cookie的内容。也就是我们希望网页在用户的机器上标识的文档内容。*/
cookie.setMaxAge(10); //设定Cookie在用户机器硬盘上的存活期为10秒。
response.addCookie(cookie); //添加cookie
response.sendRedirect("readCookie.jsp username="+username);//利用response.sendRedirect传递参数
%>