Java通过sessionId获取Session Servlet2.1之后不⽀持SessionContext⾥⾯getSession(String id)⽅法。
但是,我们可以通过HttpSessionListener和全局静态map⾃⼰实现⼀个SessionContext。
对联上下联
MySessionContext.java:
public class MySessionContext {
private static HashMap mymap = new HashMap();
public static synchronized void AddSession(HttpSession session) {
if (session != null) {
mymap.Id(), session);
}
}
public static synchronized void DelSession(HttpSession session) {
if (session != null) {
原生家庭
}
}
public static synchronized HttpSession getSession(String session_id) {
if (session_id == null)
return null;
return (HttpSession) (session_id);
}
林丹 八个避孕套}
MySessionListener.java:
public class MySessionListener implements HttpSessionListener {
public void sessionCreated(HttpSessionEvent httpSessionEvent) {
MySessionContext.Session());
}
public void sessionDestroyed(HttpSessionEvent httpSessionEvent) {
HttpSession session = Session();
小产权房新政策MySessionContext.DelSession(session);
张翰最新消息
}
}
<listener>
邯郸市教育考试院
<listener-class>listener.MySessionListener</listener-class>
</listener>
根据sessionId获取Session对象:
String sessionId = Parameter("sessionId");
HttpSession session = Session(sessionId);