美文网首页JSP专题
得到停留在网页的时间

得到停留在网页的时间

作者: 神坛下的我 | 来源:发表于2018-08-17 18:27 被阅读0次

StopTime.class

import java.util.Date;



public class StopTime {
    private int h =0;
    private int m=0;
    private int s=0;
    public StopTime(){}
    public void counttime(Date start){
        Date end = new Date();
        long howmuch=end.getTime()-start.getTime();
        h=(int)(howmuch/1000/60/60);
        howmuch=howmuch-h*60*60*1000;
        m=(int)(howmuch/1000/60);
        howmuch=howmuch-m*60*1000;
        s=(int)(howmuch/1000);
    }
    
    public int getH() {
        return h;
    }
    public void setH(int h) {
        this.h = h;
    }
    public int getM() {
        return m;
    }
    public void setM(int m) {
        this.m = m;
    }
    public int getS() {
        return s;
    }
    public void setS(int s) {
        this.s = s;
    }
    
}

index.jsp

<%@ page import="java.util.*" %>
<jsp:useBean id="mycounttime" class="com.count.StopTime" scope="page"></jsp:useBean>
<!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">
<meta http-equiv="refresh" content="10"><!-- 设置刷新时间 -->
<title>Insert title here</title>
</head>
<body>
    <%
        session.setMaxInactiveInterval(11);//设置session的有效活动时间为11s
        Date now = new Date();
        if(session.isNew()){
            session.setAttribute("start", now);
        }else{
            mycounttime.counttime((Date)session.getAttribute("start"));
        }
    %>
    <table>
        <tr>
        <td align="center">
        您登陆的时间为:<%=((Date)session.getAttribute("start")).toLocaleString() %>
        </td>
        </tr>
        <tr>
        <td align="center">
        您在本页停留的时间为:<%=mycounttime.getH() %>小时<%=mycounttime.getM() %>分钟<%=mycounttime.getS() %>秒。
        </td>
        </tr>
    </table>
    
</body>
18.PNG 19.PNG 20.PNG

相关文章

  • 得到停留在网页的时间

    StopTime.class index.jsp

  • Python爬虫 使用selenium处理动态网页

    对于静态网页,使用requests等库可以很方便的得到它的网页源码,然后提取出想要的信息。但是对于动态网页,情况就...

  • 2021-03-08得到使用攻略

    群里同学分享的,必须赞一个 得到课程导为图片方法 1、登录得到网页版相关课程,edge浏览器选择网页捕获-整页-保...

  • JS的一些常用正则

    1,得到网页上的链接地址: string matchString = @" ]+href=\s*(?:'(? ']...

  • 网页简单布局之结构与表现原则

    原来我的布局结构停留在初级阶段,看了后已经高级网页简单布局之结构与表现原则

  • 总结

    其实之前六个网页早写出来了,但是网页可简单,后来改了很长时间,感觉改网页的时间都远远超过写网页的时间。之前...

  • Web加载速度优化清单

    网页加载速度是衡量一个网页好坏的重要标准,网页遗弃率随网页加载时间的增加而增加。据说近一半的用户希望网页加载时间不...

  • 停留在时间的长河中

    在时间的长河中,人只是沧海一粟,阻挡不了时间的脚步,时光匆匆,绕过了多少岁月,你说过的记忆,早已消失,错过了太多美...

  • Python实战计划学习笔记(二)

    这次的任务是在自己写好的网页中提取所需要的信息。(当然网页不是我写的) 中间区域是为了得到评星数量观察网页对应部分...

  • 一周总结(2.1-2.7)

    周一的时候2月一号Java尖刀组初次的面试,当时还停留在我网页阶段的第三个网页(王者荣耀官网)的收尾阶段,晚上之后...

网友评论

    本文标题:得到停留在网页的时间

    本文链接:https://www.haomeiwen.com/subject/hgmtiftx.html