写:
Cookie theUsername=new Cookie("Member",q_memberId);
theUsername.setMaxAge(12*60*60);
response.addCookie(theUsername);
读:
Cookie myCookie[]=request.getCookies();
if (myCookie !=null)
{
for(int i=0;i<myCookie.length-1;i++)
{
Cookie tempCookie= myCookie[i];
if(tempCookie.getName().equals("Member"))
c_Member=tempCookie.getValue();
}
}
注意:以上写入的cookie变量路径是当前路径.要想在整个站点中都能读到这个cookie值,请在根目录写入.