![](https://iknow-base.cdn.bcebos.com/lxb/notice.png)
怎样统计表的访问次数
2个回答
2017-02-20 · 诚信经营,以人为本,客户致上!
文芳阁传媒是一个专业在网络上承接企业,个人软文代写以及软文推广的平台。以低价格把新闻发布在新浪、网易、新华、凤凰、腾讯、央视等3000家门户及地方网站媒体,以塑造公司品牌的知名度和公信力.
向TA提问
关注
![](https://wyw-base.cdn.bcebos.com/pc-content/follow.gif)
展开全部
一种,单页面统计。就是说,只要点击这个页面就会统计一次。<%@ page contentType="text/html;charset=GB2312" %> <html> <head> <title> java计数器程序片 </title> </head> <body> <%!//在这种标记中定义的变量为全局变量 int count=0; synchronized void count(){ count++; } %> <% count(); out.println("这是第"+count+"个访问者!"); %> </body> </html>
2
第二中,是利用jsp的内置对象application进行统计。这个程序结果运行分析,也是访问一次页面统计一次。感觉还是不够好。真正满意的是浏览器打开网页,到关闭网页算一次,这样统计比较实际。 <%@ page contentType="text/html;charset=GB2312" %> <html> <head> <title> java计数器程序 </title> </head> <body> <% if(application.getAttribute("count")==null){ application.setAttribute("count",new Integer(0)); } Integer count=(Integer)application.getAttribute("count"); application.setAttribute("count",new Integer(count.intValue()+1)); count=(Integer)application.getAttribute("count"); %> <center>这是第<%=count.intValue()%>个访问者!</center> </body> </html>。
2
第二中,是利用jsp的内置对象application进行统计。这个程序结果运行分析,也是访问一次页面统计一次。感觉还是不够好。真正满意的是浏览器打开网页,到关闭网页算一次,这样统计比较实际。 <%@ page contentType="text/html;charset=GB2312" %> <html> <head> <title> java计数器程序 </title> </head> <body> <% if(application.getAttribute("count")==null){ application.setAttribute("count",new Integer(0)); } Integer count=(Integer)application.getAttribute("count"); application.setAttribute("count",new Integer(count.intValue()+1)); count=(Integer)application.getAttribute("count"); %> <center>这是第<%=count.intValue()%>个访问者!</center> </body> </html>。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询