세션 ID를 기반으로 세션 객체 가져오기
1648 단어 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.put(session.getId(), session);
}
}
public static synchronized void DelSession(HttpSession session) {
if (session != null) {
mymap.remove(session.getId());
}
}
public static synchronized HttpSession getSession(String session_id) {
if (session_id == null)
return null;
return (HttpSession) mymap.get(session_id);
}
}
MySessionListener.java:
public class MySessionListener implements HttpSessionListener {
public void sessionCreated(HttpSessionEvent httpSessionEvent) {
MySessionContext.AddSession(httpSessionEvent.getSession());
}
public void sessionDestroyed(HttpSessionEvent httpSessionEvent) {
HttpSession session = httpSessionEvent.getSession();
MySessionContext.DelSession(session);
}
}
web.xml :
<listener>
<listener-class>listener.MySessionListener</listener-class>
</listener>
sessionId Session :
String sessionId = request.getParameter("sessionId");
HttpSession session = MySessionContext.getSession(sessionId);
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
JWT로 세션을 관리하지 마십시오.세상에는 JWT(JOSE/JWS/JWE)로 세션 관리를 해서는 안 된다는 기사가 2017년부터 산 정도 있는데 왠지 JWT에서 세션 관리를 하려고 하는 사람이 있다. 번역 기사이거나 암호의 설명이 너무 길거나 해서,...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.