根据sessionId获取session


import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpSession;

public class EgoSessionContext {
	private static EgoSessionContext instance = new EgoSessionContext();
	private Map<String, HttpSession> sessionMap;

	private EgoSessionContext() {
		sessionMap = new HashMap<String, HttpSession>();
	}

	public static EgoSessionContext getInstance() {
		return instance;
	}

	public synchronized void addSession(HttpSession session) {
		if (session != null) {
			sessionMap.put(session.getId(), session);
		}
	}

	public synchronized void delSession(HttpSession session) {
		if (session != null) {
			sessionMap.remove(session.getId());
		}
	}

	public synchronized HttpSession getSession(String sessionId) {
		if (sessionId == null)
			return null;
		return sessionMap.get(sessionId);
	}
}





import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpSession;

public class EgoSessionContext {
	private static EgoSessionContext instance = new EgoSessionContext();
	private Map<String, HttpSession> sessionMap;

	private EgoSessionContext() {
		sessionMap = new HashMap<String, HttpSession>();
	}

	public static EgoSessionContext getInstance() {
		return instance;
	}

	public synchronized void addSession(HttpSession session) {
		if (session != null) {
			sessionMap.put(session.getId(), session);
		}
	}

	public synchronized void delSession(HttpSession session) {
		if (session != null) {
			sessionMap.remove(session.getId());
		}
	}

	public synchronized HttpSession getSession(String sessionId) {
		if (sessionId == null)
			return null;
		return sessionMap.get(sessionId);
	}
}

你可能感兴趣的:(java,session)