论坛统计在线人数
1 登录的action中 ,如果登录成功:
Integer c = (Integer) ActionContext.getContext().getApplication().get("userCount");
if(c== null){
ActionContext.getContext().getApplication().put("userCount", 1);
}else{
<span style="white-space:pre"> </span>ActionContext.getContext().getApplication().put("userCount", c+1);
}2.登录后的界面添加:
<%
Integer userCount= (Integer)application.getAttribute("userCount");%>
<div>在线人数:<%=userCount %></div>3.用户推出登录时:
AppAccount acc = (AppAccount) getRequest().getSession().getAttribute("curr_user");
if(acc!=null){
getRequest().getSession().removeAttribute("curr_user");
Integer cou = (Integer) ActionContext.getContext().getApplication().get("userCount");
ActionContext.getContext().getApplication().put("userCount",new Integer(cou-1));
}声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。
- 上一篇: JavaScript的数组和Java的数组的差别
- 下一篇: 基于swoole搭建聊天室程序
