?
?
?
二、
<%@page import="java.text.SimpleDateFormat"%> <%@page import="java.util.Date"%> <%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> <body><%// 獲取 所需要格式的當前系統時間Date date=new Date();SimpleDateFormat sdf=new SimpleDateFormat("MM:hh:ss");String nowTime=sdf.format(date);//設置cookieCookie c=new Cookie("lastTime",nowTime);response.addCookie(c);//將cookie 寫入到響應流 響應給請求的客戶端Cookie []cs=request.getCookies();//創建cookie的數組 因為有很多boolean tag=false; //定義Boolean的變量 記錄首次訪問if(cs!=null&&cs.length>0){for(Cookie c1:cs){if(c1.getName().equals("lastTime")){tag=true;out.write("上次的訪問時間 "+c1.getValue());break;}}}if(!tag){out.write("你是首次訪問!");}%></body> </html>
?