使用此代码管理您的活动会话并按其ID获取会话,然后您可以调用此会话并在需要时使其无效:
public class SessionListener implements HttpSessionListener
{
private static Map<String, HttpSession> map = new
HashMap<String, HttpSession>();
public void sessionCreated(HttpSessionEvent event)
{
String id = event.getSession().getId();
logger.debug("session created : " + id);
// STORE THE SESSOIN FOR EXAMPLE IN DATABASE
map.put(id, event.getSession());
}
public static HttpSession getHttpSession(String sessionID)
{
return sessionObjectMap.get(sessionID);
}
public void sessionDestroyed(HttpSessionEvent event)
{
// get the destroying session...
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2098 次 |
| 最近记录: |