访问统计java
public class Counter {
private int count;
// 每访问一次,计数器自加一
public int getCount() {
return ++count;
}
public void setCount(int count) {
this.count = count;
}
}
<%-- 定义一个 session 范围内的计数器 记录个人访问信息 --%>
<jsp:useBean id="personCount" class="com.helloweenvsfei.jspweb.bean.Counter" scope="session" />
<%-- 定义一个 application 范围内的计数器 记录所有人的访问信息 --%>
<jsp:useBean id="totalCount" class="com.helloweenvsfei.jspweb.bean.Counter" scope="application" />
<div align="center">
<form action="method.jsp" method="get">
<fieldset style='width: 300'>
<legend>计数器</legend>
<table align="center" width="400">
<tr>
<td width=150 align="right" style="font-weight:bold; ">您的访问次数:</td>
<td>
<%-- 获取个人的 访问次数 --%>
<jsp:getProperty name="personCount" property="count" /> 次
</td>
</tr>
<tr>
<td width=150 align="right" style="font-weight:bold; ">总共的访问次数:</td>
<td>
<%-- 获取所有人的 访问次数 --%>
<jsp:getProperty name="totalCount" property="count" /> 次
</td>
</tr>
</table>
</fieldset>
</form>
</div>
希望你能帮到你
㈡ java 怎样统计系统当前在线人数
统计在线人数的方式不同(比如登录人数或者页面访问人数)具体的实现方式不同,但是记录统计人数的方法是一样的1。定义一个静态变量或者在application作用于放置一个变量存放在线人数,如果是登录人数,则在用户登录时+1,如果是页面访问人数就添加一个监听器listener进行监听(sessionId) 如果有用户访问页面就+1
㈢ 网站访问量统计java代码怎样写
<DIV class="h">
<%-- 记录网站访问次数 --%>
<%
Integer counter = (Integer)application.getAttribute("counter"); //先从application里面获取计数器的key的值
if(counter==null){
//如果该值为null,说明第一次访问
application.setAttribute("counter",1);
counter=(Integer)application.getAttribute("counter");
}else {
//如果该值不为空,取出来进行累加
int i = counter.intValue();
i++;
application.setAttribute("counter",i);//累加后再放进去
}
%>
<% User user =(User)session.getAttribute("users"); %>
<%="欢迎"+user.getName() %> |您是第<%=counter.intValue()%>位访客
</DIV>
谢谢~