#
mrzhssss
2022-07-28 e6a77efb062a864f012d88ebd6efb45c81f55591
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package com.slcf.filter;
 
import java.util.HashMap;
 
import javax.servlet.http.HttpSession;
 
public class MySessionContext {
    private static MySessionContext instance;
    private HashMap<Object, Object> mymap;
    
    private MySessionContext() {
        mymap=new HashMap();
    }
    
    public static MySessionContext getInstance(){
        if(instance == null){
            instance = new MySessionContext();
        }
        return instance;
    }
    
    public synchronized void AddSession(HttpSession session){
        if(session != null){
            mymap.put(session.getId(), session);
        }
    }
    
    public synchronized void DelSession(HttpSession session){
        if(session != null){
            mymap.remove(session.getId());
        }
    } 
    
    public synchronized HttpSession getSession(String sessionId){
        if(sessionId == null){
            return null;
        }
        return (HttpSession) mymap.get(sessionId);
    }    
}