日期:2014-05-17 浏览次数:20756 次
public class OnlineListener implementss HttpSessionListener private int onlineCount; public OnlineListener() {onlineCount=0; } public void sessionCreated(HttpSessionEvent sessionEvent) { onlineCount++; sessionEvent.getSession().getServletContext().setAttribute("online",new Integer(onlineCount)); } public void sessionDestroyed(HttpSessionEvent sessionEvent) { onlineCount--; sessionEvent.getSession().getServletContext().setAtrribute("online",new Integer(onlineCount)); } }
------解决方案--------------------
我们刚学JSP,学了个application的内置对象……可以用它实现在线用户统计,好像,你可以看看,我也是刚学的,一起讨论讨论
index.jsp页面如下:
<%
Integer acount;
acount = (Interger)application.getAttrubute("acounter");
if(acount==null){
acount = new Integer(1);
}else{
acount = new Integer(requset.intValue()+1);
}
application.setAttribute("acounter","acount");
%>
<table>
<tr>
<th>在线用户为</th>
<Td><%=application.getAttribute("acounter")%></Td>
</tr>
</table>