有谁做过论坛在线统计功能??? 有谁做过论坛在线统计功能???能不能说下原理!!!!! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你可以用以下的代码做一个在线统计。统计目前在线总数。----<%Vector topUserList=(Vector)application.getAttribute("list");if(topUserList==null){ topUserList=new Vector();}out.println(topUserList.size());%><%if(topUserList.size()>0){%>列出在线人数------<% for(int i=0;i<topUserList.size();i++) { out.print(topUserList.elementAt(i).toString()); if(i!=topUserList.size()-1) out.print(","); }}%>。</p> 我实现的JAVA聊天室就可以实现这样的功能.关于显示在线的人可以采用krikxu() ( ) 信誉:100 的办法要是只要显示论坛的人数.个人观点:采用这个不好.采用Session更好不过有点需要注意用户存在正常退出和非法退出:一般的功能只针对于正常退出.要是用户非法退出.这样的功能就无法达到效果.可以采用代码去监测是否在线.比方说:如果用户在2个小时以后还是没什么操作.我们可以假定用户已经退出了论坛.我们把他请出去.具体时间楼主自己斟酌 利用servlert的sessionListener,很简单就实现了我来接分给分后联系我,发出全部源代码. 可以通过session得到在线人数。然后可以一一列出,对于非正常退出的可以来个sessionListener. 可以通过session得到在线人数。然后可以一一列出,对于非正常退出的可以来个sessionListener. 如何获得在线用户package SessionCounter;import javax.servlet.*;import javax.servlet.http.*;import java.util.*;import com.oztime.right.UserObject;public class SessionCounter implements HttpSessionListener {private static int activeSessions = 0;private static Vector v= new Vector();public void sessionCreated(HttpSessionEvent se) {}public static void createsession(HttpSessionEvent se ) {UserObject user1 =(UserObject)se.getSession().getAttribute("UserObject");if(v.contains(user1)==false){v.add(user1);activeSessions++;System.out.println("===================用户名称=================="+user1.getName());System.out.println("===================用户数量=================="+activeSessions);}}public void sessionDestroyed(HttpSessionEvent se) {System.out.println("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%");UserObject user2=(UserObject)se.getSession().getAttribute("UserObject");if(v.contains(user2)==true){v.remove(user2);activeSessions--;System.out.println("===================removed=================="+user2.getName());}}public static void Destroysession(UserObject user) {//System.out.println("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%");//UserObject user3=(UserObject)se.getSession().getAttribute("UserObject");System.out.println("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"+user.getName());if(v.contains(user)==true){v.removeElement(user);activeSessions--;System.out.println("====================================="+user.getName()+"---退出登录!!!");}} public static int getActiveSessions() {return activeSessions;}public static Vector getVector() {return v;}}在用户登陆后调用的SessionCounter.createsession(new HttpSessionEvent(session));SessionCounter.Destroysession(user); //注user 为用户实体 jsp中怎么实现两个页面之间的相互跳转 请问<htmlex:cp/>是哪里的标签,js里的,还是struts里的??? 谢谢大家,希望大家解析一下,下面代码怎么实现图片连接?详细!!!! j2ee网站前台和后台管理方法是写在一个类里还是分开写? 简易购物 求助! iis与tomcat整合??? servlet输出页面时报错 oracle与mysql servlet中得到参数的中文问题 请问在javascript的函数里面可不可以调用java的方法?如果可以,应该怎么调用呢? 用eclipse写struts时发现的问题,大家帮帮忙 如何判断表单被提交后再进行页面跳转!
统计目前在线总数。----
<%
Vector topUserList=(Vector)application.getAttribute("list");
if(topUserList==null)
{
topUserList=new Vector();
}
out.println(topUserList.size());
%><%
if(topUserList.size()>0)
{
%>
列出在线人数------
<%
for(int i=0;i<topUserList.size();i++)
{
out.print(topUserList.elementAt(i).toString());
if(i!=topUserList.size()-1)
out.print(",");
}
}
%>。
</p>
关于显示在线的人可以采用krikxu() ( ) 信誉:100 的办法
要是只要显示论坛的人数.个人观点:采用这个不好.
采用Session更好
不过有点需要注意
用户存在正常退出和非法退出:
一般的功能只针对于正常退出.
要是用户非法退出.这样的功能就无法达到效果.
可以采用代码去监测是否在线.
比方说:如果用户在2个小时以后还是没什么操作.我们可以假定用户已经退出了论坛.
我们把他请出去.
具体时间楼主自己斟酌
我来接分给分后联系我,发出全部源代码.
对于非正常退出的可以来个sessionListener.
可以通过session得到在线人数。然后可以一一列出,
对于非正常退出的可以来个sessionListener.
import javax.servlet.http.*;
import java.util.*;
import com.oztime.right.UserObject;public class SessionCounter implements HttpSessionListener {private static int activeSessions = 0;
private static Vector v= new Vector();
public void sessionCreated(HttpSessionEvent se) {
}
public static void createsession(HttpSessionEvent se ) {
UserObject user1 =(UserObject)se.getSession().getAttribute("UserObject");
if(v.contains(user1)==false){
v.add(user1);
activeSessions++;
System.out.println("===================用户名称=================="+user1.getName());
System.out.println("===================用户数量=================="+activeSessions);
}}public void sessionDestroyed(HttpSessionEvent se) {
System.out.println("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%");
UserObject user2=(UserObject)se.getSession().getAttribute("UserObject");
if(v.contains(user2)==true){
v.remove(user2);
activeSessions--;
System.out.println("===================removed=================="+user2.getName());
}}
public static void Destroysession(UserObject user) {
//System.out.println("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%");
//UserObject user3=(UserObject)se.getSession().getAttribute("UserObject");
System.out.println("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"+user.getName());
if(v.contains(user)==true){
v.removeElement(user);
activeSessions--;
System.out.println("====================================="+user.getName()+"---退出登录!!!");
}} public static int getActiveSessions() {
return activeSessions;}public static Vector getVector() {
return v;
}
}在用户登陆后调用的
SessionCounter.createsession(new HttpSessionEvent(session));SessionCounter.Destroysession(user); //注user 为用户实体