网站访问计数方法?

saint13 2005-12-07 09:40:23
用jsp实现网站访问计数的都有哪些方法?
请大家指点.
...全文
212 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
climb011358 2005-12-08
  • 打赏
  • 举报
回复
<%@ page contentType="text/html; charset=GBK" %>
<html>
<head>
<title>synchronized计数器示例</title>
</head>
<body>
<center>
<h3>synchronized计数器示例</h3>
<%
//使用整数类存放访问数
Integer counter = null;
//锁住application对象,不给其它用户访问,当运行完{}符号的代码后,再释放application对象
synchronized (application) {
//取得application对象的访问数
counter = (Integer) application.getAttribute("basic.counter");
//如果访问数为空,重新创建访问数
if (counter == null)
counter = new Integer(0);
//累加访问数
counter = new Integer(counter.intValue() + 1);
//在application对象内保存访问数
application.setAttribute("basic.counter", counter);
}
%>
<p>您是第<font color="red"><%=counter.intValue()%></font>位访问者.</p>
</center>
</body>
</html>
killson 2005-12-07
  • 打赏
  • 举报
回复
关注。。
xiongbing528 2005-12-07
  • 打赏
  • 举报
回复
count++
xiongbing528 2005-12-07
  • 打赏
  • 举报
回复
public synchronized void do{
application.setAttribute("count",count);
写入文件。。}

fog628 2005-12-07
  • 打赏
  • 举报
回复
1>.
每一次访问都会创建一个新的session, 有一个HttpSessionListener接口,
public void sessionCreated(HttpSessionEvent se) {
//当每次创建一个新的session时会调用
}
public void sessionDestroyed(HttpSessionEvent se) {
//session失效时候调用
}

所以你可以在新创建一个session时使一个记数器(可以是DB或文件)加1

2>.在web.xml中配置listener
<listener>
<listener-class>session.SessionCounter</listener-class>
</listener>
saint13 2005-12-07
  • 打赏
  • 举报
回复
请大家说一些思路,就可以了啊.Thanks!

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧