日期:2014-05-17 浏览次数:20689 次
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <%! String username=""; String password=""; boolean point=false; %> <% if (point) { String name = request.getParameter("name"); String word = request.getParameter("word"); Cookie c = new Cookie("name", name); c.setMaxAge(24 * 3600); response.addCookie(c); Cookie k = new Cookie("word", word); k.setMaxAge(24 * 3600); response.addCookie(k); Cookie[] cookies = request.getCookies(); if (cookies!= null) { for (int i = 0; i < cookies.length; i++) { System.out.println(cookies[i].getValue()); if (cookies[i].getName().equals("name")) { username = cookies[i].getValue().trim(); System.out.println(username); } if (cookies[i].getName().equals("word")) { password = cookies[i].getValue().trim(); System.out.println(password); } } } } point = true; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> </head> <body> <form method="get" action="cookielogin.jsp"> 用户名: <input type="text" name="name" value="<%=username%>" /> <br> 密 码: <input type="password" name="word" value="<%=password%>" /> <br> <input type="submit" value="登陆" /> </form> </body> </html>