【文件属性】:
文件名称:java 同一用户不能同时登陆问题
文件大小:3KB
文件格式:JAVA
更新时间:2016-08-14 03:30:54
session监听
好用简单package com.jswf.modle.sysuser;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
import org.apache.struts2.ServletActionContext;
import com.jswf.sys.SysParams;
import com.jswf.vo.UserVo;
import com.opensymphony.xwork2.ActionContext;
public class DialogHttpSessionListner implements HttpSessionListener {
private static Map httpssessionmap = new Hashtable();
// private UserVo uservo=new UserVo();
private static List userIds = new ArrayList();
public void sessionCreated(HttpSessionEvent se) {
}
public void sessionDestroyed(HttpSessionEvent event) {
// HttpSession session = getSessionByID(UserVo);
if (userIds != null && userIds.size()>0) {
for (String userid : userIds) {
UserVo u =(UserVo) event.getSession().getAttribute(SysParams.SESSION_USER);
if (httpssessionmap.containsKey(userid)&&httpssessionmap.get(userid).equals(event.getSession())) {
//userIds.remove(userid);
httpssessionmap.remove(userid);
if(u!=null && userid.equals(u.getUserId()+"")){
event.getSession().setAttribute(SysParams.SESSION_USER,null);
}
System.out.println("session.getId()=" + userid);
}
}
}
/*
* if(httpssessionmap.containsKey(event.getSession().getId())){
* httpssessionmap.remove(event.getSession().getId()); }
*/
// System.out.println("session.getId()="+event.getSession().getId());
}