一、useCookie.html
Using cookie
二、useCookie.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>use cookie jsp <%String sname = request.getParameter("name");String ssex = request.getParameter("sex");String sbooks = request.getParameter("books");Cookie nameCookie = new Cookie("name", sname);Cookie sexCookie = new Cookie("sex", ssex);Cookie bookCookie = new Cookie("books", sbooks);response.addCookie(nameCookie);response.addCookie(sexCookie);response.addCookie(bookCookie);response.sendRedirect("responseCookie.jsp");%>
三、responseCookie.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>得到 Cookie中的资料信息 <%Cookie cookies[]=request.getCookies();int n = cookies.length;String name="", sex="", articl="";for(int i=0; i<%=name %>hello。下面就是您的个人资料啦。。 <%out.println("性别:
");if(sex.equals("F")) out.println("img src='images/g.jpg'>Girl..");else out.println("img src='images/b.jpg'>Boy...
");%>
Cookie的一个简单的小例子。。