有一种方案如下:
openDb.executeQuery("update onlineuser set logondate=sysdate where username='"+name+"'");
如果用户在线的话,把logondate记为当前时间
openDb.executeQuery("delete from onlineuser where (logondate+1/360)<sysdate");
如果用户最后在线时间与当前时间大于4分钟,说明用户已经离开,在onlineuser中删除此用户
如果这两句sql语句都写在iframe中,当用户离线时,iframe也关闭了,第二句
openDb.executeQuery("delete from onlineuser where (logondate+1/360)<sysdate");怎么执行呢???还用一种方案如下:
登录加入:
<jsp:useBean id="monitor" scope="application" class="java.util.HashMap" />monitor.put(session,user.getUserName());//user是个对象类
UserMap map = new UserMap();
map.setMap(monitor);
session.setAttribute("Binder.object",map);UserMap是一个实现HttpSessionListener的类:
import javax.servlet.http.HttpSessionBindingEvent;
import javax.servlet.http.HttpSessionBindingListener;
import java.util.*;public class UserMap implements HttpSessionBindingListener {
private HashMap map; public void valueBound(HttpSessionBindingEvent event) {
} public void valueUnbound(HttpSessionBindingEvent event) {
map.remove(event.getSession());
} public void setMap(HashMap map){
this.map = map;
}
}退出时jsp:
((HashMap)application.getAttribute("monitor")).remove(session);
session.invalidate();查询在线用户jsp:
HashMap monitor = ((HashMap)application.getAttribute("monitor"));
Iterator keyIter = monitor.keySet().iterator(); while(keyIter.hasNext()){
HttpSession https = (HttpSession)keyIter.next(); out.println("<tr>"); out.println("<td bgcolor=\"EEEEEE\" width=\"5%\">");
out.println("<div align=\"center\">" + (String)monitor.get(https) + "</div>");
out.println("</td>");
....
....
}
openDb.executeQuery("update onlineuser set logondate=sysdate where username='"+name+"'");
如果用户在线的话,把logondate记为当前时间
openDb.executeQuery("delete from onlineuser where (logondate+1/360)<sysdate");
如果用户最后在线时间与当前时间大于4分钟,说明用户已经离开,在onlineuser中删除此用户
如果这两句sql语句都写在iframe中,当用户离线时,iframe也关闭了,第二句
openDb.executeQuery("delete from onlineuser where (logondate+1/360)<sysdate");怎么执行呢???还用一种方案如下:
登录加入:
<jsp:useBean id="monitor" scope="application" class="java.util.HashMap" />monitor.put(session,user.getUserName());//user是个对象类
UserMap map = new UserMap();
map.setMap(monitor);
session.setAttribute("Binder.object",map);UserMap是一个实现HttpSessionListener的类:
import javax.servlet.http.HttpSessionBindingEvent;
import javax.servlet.http.HttpSessionBindingListener;
import java.util.*;public class UserMap implements HttpSessionBindingListener {
private HashMap map; public void valueBound(HttpSessionBindingEvent event) {
} public void valueUnbound(HttpSessionBindingEvent event) {
map.remove(event.getSession());
} public void setMap(HashMap map){
this.map = map;
}
}退出时jsp:
((HashMap)application.getAttribute("monitor")).remove(session);
session.invalidate();查询在线用户jsp:
HashMap monitor = ((HashMap)application.getAttribute("monitor"));
Iterator keyIter = monitor.keySet().iterator(); while(keyIter.hasNext()){
HttpSession https = (HttpSession)keyIter.next(); out.println("<tr>"); out.println("<td bgcolor=\"EEEEEE\" width=\"5%\">");
out.println("<div align=\"center\">" + (String)monitor.get(https) + "</div>");
out.println("</td>");
....
....
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货