⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 onlinelistener.java

📁 一套购物车项目。电子商务系统。实现了前台和后台的业务逻辑。
💻 JAVA
字号:
package com.softfz.jn0708.listener;

import java.util.Vector;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpSessionAttributeListener;
import javax.servlet.http.HttpSessionBindingEvent;

/**
 * 会话监听
 * @author student
 *
 */
public class OnlineListener implements HttpSessionAttributeListener{

	public void attributeAdded(HttpSessionBindingEvent event) {
//		String name =event.getName();
//		Object value = event.getValue();
//		ServletContext context = event.getSession().getServletContext();
//		
//		if(name.equals("user")){
//			
//			Vector online = (Vector) context.getAttribute("online");
//			if(online==null){
//				online= new Vector();
//				context.setAttribute("online",online);
//			}
//			online.add(value);		
//			
//		}
//		if(name.equals("adminuser")){
//
//			Vector online = (Vector) context.getAttribute("aonline");
//			if(online==null){
//				online= new Vector();
//				context.setAttribute("aonline",online);
//			}
//			online.add(value);	
//		}
		
		
	}

	public void attributeRemoved(HttpSessionBindingEvent event) {
		String name =event.getName();
		Object value = event.getValue();
		ServletContext context = event.getSession().getServletContext();
		if(name.equals("user")){			
			Vector online = (Vector) context.getAttribute("online");
			if(online!=null){
				online.remove(value);
			}					
		}
		if(name.equals("adminuser")){
			Vector online = (Vector) context.getAttribute("aonline");
			if(online!=null){
				online.remove(value);
			}	
		}
		
	}

	public void attributeReplaced(HttpSessionBindingEvent arg0) {
	
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -