<%
int flag=0;
Cookie[] cookies = request.getCookies();
if (cookies != null && cookies.length > 0) {
for (Cookie c : cookies) {
if ("lasttime".equals(c.getName())) {
String timeValue = c.getValue();
String decodetime = URLDecoder.decode(timeValue, "utf-8");
out.print("您上次的访问时间为:"+decodetime);
flag=1;
break;
}
}
}
Date date = new Date();
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
String time = format.format(date);
String encode = URLEncoder.encode(time, "utf-8");
Cookie cookie = new Cookie("lasttime", encode);
cookie.setMaxAge(60*60*24*30);
response.addCookie(cookie);
if (flag == 0) {
out.print("首次登陆,欢迎您");
}
%>
jsp实现显示上一次访问页面时间
最新推荐文章于 2021-01-08 19:19:50 发布