timecomputelistener.java

来自「一个成熟的论坛」· Java 代码 · 共 36 行

JAVA
36
字号
package com.singnet.listener;

import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

import com.singnet.data.*;
import com.singnet.util.TimeComputeUtils;

public class TimeComputeListener implements HttpSessionListener
{

	public void sessionCreated(HttpSessionEvent event)
	{
		// TODO Auto-generated method stub
		event.getSession().setMaxInactiveInterval(60 * 30);
	}

	public void sessionDestroyed(HttpSessionEvent event)
	{
		// TODO Auto-generated method stub
		HttpSession session = event.getSession();
		if(session.getAttribute(Constants.SESSION_UID) != null) {
			String userID = String.valueOf(session.getAttribute(Constants.SESSION_UID));
			OnlineBean olb = TimeComputeUtils.getOnlineBeanByUserID(userID);
			if(null != olb) {
				TimeComputeUtils.ONLINE_LIST.remove(olb);
				olb.setOnline(false);
			}
		}
		session.invalidate();
	}
	

}

⌨️ 快捷键说明

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