当前位置: 首页 > news >正文

查询做导员的网站/工作手机

查询做导员的网站,工作手机,做 b2b平台的网站,网站建设和开发HttpSessionListener用于监听用户session的创建和销毁,实现该接口的监听器需要实现sessionCreated和sessionDestroyed方法 HttpSessionAttributeListener用于监听HttpSession范围内属性的变化,需实现attributeAdded、attributeRemoved、attributeReplace…

HttpSessionListener用于监听用户session的创建和销毁,实现该接口的监听器需要实现sessionCreated和sessionDestroyed方法

HttpSessionAttributeListener用于监听HttpSession范围内属性的变化,需实现attributeAdded、attributeRemoved、attributeReplaced三个方法,同ServletRequestAttributeListener、ServletContextAttributeListener的使用方法相似,具体参考前两篇博客

1. 实现Listener接口OnlineListener.java,统计在线用户的信息

package test;

import javax.servlet.*;
import javax.servlet.http.*;import java.util.*;
public class OnlineListener implements HttpSessionListener{
//当用户与服务器之间开始session时触发该方法
public void sessionCreated(HttpSessionEvent se){
HttpSession session = se.getSession();
ServletContext application = session.getServletContext();
//获取session ID
String sessionId = session.getId();
//如果是一次新的会话
if (session.isNew()){
String user = (String)session.getAttribute("user");
//未登录用户当游客处理
user = (user == null) ? "游客" : user;
Map<String , String> online = (Map<String , String>)application.getAttribute("online");
if (online == null){
online = new Hashtable<String , String>();
}
//将用户在线信息放入Map中
online.put(sessionId , user);
application.setAttribute("online" , online);
}
}
//当用户与服务器之间session断开时触发该方法
public void sessionDestroyed(HttpSessionEvent se){
HttpSession session = se.getSession();
ServletContext application = session.getServletContext();
String sessionId = session.getId();
Map<String , String> online = (Map<String , String>)application.getAttribute("online");
if (online != null){
//删除该用户的在线信息
online.remove(sessionId);
}
application.setAttribute("online" , online);
}
}
2. 显示在线用户的信息online.jsp

<%@ page contentType="text/html; charset=GBK" language="java"
errorPage=""%>
<%@ page import="java.util.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>用户在线信息</title>
<meta name="website" content="http://www.crazyit.org" />
</head>
<body>
在线用户:
<table width="400" border="1">
<%
Map<String, String> online = (Map<String, String>) application.getAttribute("online");
for (String sessionId : online.keySet()) {
%>
<tr>
<td><%=sessionId%>
<td><%=online.get(sessionId)%>
</tr>
<%}%>
</body>
</html>

http://www.lbrq.cn/news/1108891.html

相关文章:

  • wordpress降低版本/怎样优化网站排名靠前
  • 测试网站免费空间/如何推广公司网站
  • 医院网站党支部机构建设/自媒体平台
  • 民权平台网站建设/沈阳优化网站公司
  • 建立个人网站需要什么/网页制作成品模板网站
  • 网站快照是自己做的吗/滨州seo招聘
  • 四川省人民政府服务热线/优化疫情政策
  • 可以注销的网站/15个常见关键词
  • 济宁住房和城乡建设厅网站首页/下载班级优化大师app
  • 网站建立基本流程/西安关键词优化服务
  • 西安市今天发生的重大新闻/山东公司网站推广优化
  • 为什么python不适合开发网站/网站建设的基本
  • 昆山做轮胎网站/营销说白了就是干什么的
  • 合肥最好的网站建设公司排名/小程序怎么开发
  • 网站建设建设/网站seo推广哪家值得信赖
  • WordPress多条件搜索/seo整站优化方案案例
  • 访问国外网站用什么dns/seo服务外包公司
  • php网站开发实例电子版/亚马逊查关键词排名工具
  • 手机禁止网站跳转页面/建设网官方网站
  • 北京市建设工程信息网如何登录/seo网站优化方
  • 网站开发服务计入什么科目/网站页面优化方法
  • 哪里有做营销型网站的公司/公司网络推广该怎么做
  • 海南网站制作/seo技术顾问阿亮
  • 广告网站设计公司 作用/学电商出来一般干什么工作
  • 十五种网络营销工具/seo臻系统
  • fuzzz的wordpress模板/高平网站优化公司
  • 最好的免费网站空间/河北seo基础知识
  • 桂林手机网站制作/常用的seo网站优化排名
  • 高端电子商务网站建设/b2b平台网站
  • 扁平化中文网站模板下载/搜索引擎推广的关键词
  • Maven 依赖管理
  • Visual Studio Code(VSCode)中设置中文界面
  • Rust Web 全栈开发(十):编写服务器端 Web 应用
  • Netty集群方案详解与实战(Zookeeper + Redis + RabbitMQ)
  • [spring6: PointcutAdvisor MethodInterceptor]-简单介绍
  • react/vue vite ts项目中,自动引入路由文件、 import.meta.glob动态引入路由 无需手动引入