Come on,everybody,tell me how to do it!
解决方案 »
- validationEngine验证
- mysql Statement parameter 1 not set.
- 做信息发布系统如何把要显示的信息按照特定的格式显示出来
- 急急急 谁帮我看一下我用SSH做的一个系统以前好用今天突然不好使了
- 首页CSS优化问题
- 数据池配置问题
- 求一个完整的JAVA代码,功能是一台电脑上的JSP程序,想使用另一个电脑上的JAVA类
- 求google TTS 语速控制和回音清除API或方法!
- 问大家关于在jsp+javabean的开发中,数据的封装问题
- Servlet and Tomcat ???
- windows 98 用jsp 应该需要什么环境.怎么配置.
- 如果大家有问题,请到JAVA版去问吧,那里人比较好。
Interface HttpSessionContext--------------------------------------------------------------------------------
Deprecated. As of Java(tm) Servlet API 2.1 for security reasons, with no replacement. This interface will be removed in a future version of this API. public abstract interface HttpSessionContextVersion:
$Version$
Author:
Various
See Also:
HttpSession, HttpSessionBindingEvent, HttpSessionBindingListener--------------------------------------------------------------------------------Method Summary
java.util.Enumeration getIds()
Deprecated. As of Java Servlet API 2.1 with no replacement. This method must return an empty enumeration and will be removed in a future version of this API.
HttpSession getSession(java.lang.String sessionId)
Deprecated. As of Java Servlet API 2.1 with no replacement. This method must return null and will be removed in a future version of this API.
Method Detail
getSession
public HttpSession getSession(java.lang.String sessionId)
Deprecated. As of Java Servlet API 2.1 with no replacement. This method must return null and will be removed in a future version of this API.--------------------------------------------------------------------------------getIds
public java.util.Enumeration getIds()
Deprecated. As of Java Servlet API 2.1 with no replacement. This method must return an empty enumeration and will be removed in a future version of this API.
登录加入:
<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>");
....
....
}
不是我想要的,我想要的是得到所有被建立的session对象。而且我也不想在客户端做个计时刷新。我要利用session会自动的由于浏览器的关闭而失效这个性质。
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;
}
}
上面的就达到你的目的(我要利用session会自动的由于浏览器的关闭而失效这个性质)
monitor.put(session,new Date());//user是个对象类所有session 都放在 HashMap monitor 里,你可以把他们列出来,显示登陆时间,那不是完成你的目的吗。