cookie ? 利用cookie实现 显示上次访问时间?
                                                            生活随笔
收集整理的這篇文章主要介紹了
                                cookie  ? 利用cookie实现  显示上次访问时间?
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.                        
                                ?
?
?
二、
<%@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>?
轉載于:https://www.cnblogs.com/ZXF6/p/11111439.html
總結
以上是生活随笔為你收集整理的cookie ? 利用cookie实现 显示上次访问时间?的全部內容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: 【English】六、am,is,are
- 下一篇: Use Windows Azure AD
