session管理

public class SessionManager
{

    private static SessionManager sessionManager = null;

    public static SessionManager getInstance()
    {

        if (sessionManager == null)
        {
            sessionManager = new SessionManager();
        }
        return sessionManager;
    }

    private ThreadLocal<HttpSession> sessionHolder = new ThreadLocal<HttpSession>();

    private ThreadLocal<ApplicationContext> applicationContextHolder = new ThreadLocal<ApplicationContext>();

    public void setSession(HttpSession session)
    {
        if (session != sessionHolder.get())
        {
            sessionHolder.set(session);
        }
    }

      private HttpSession getSession()
    {

        return sessionHolder.get();
    }

    public String getLoginId()
    {
                loginId = (String) this.getSession().getAttribute("loginId");
              return loginId;
    }

    public Object getLoginUser()
    {
                    result = this.getSession().getAttribute("LoginUser");
            }

    public void setApplicationContext(ApplicationContext applicationContext)
    {

        if (applicationContext != applicationContextHolder.get())
        {

            applicationContextHolder.set(applicationContext);

        }

    }

    public ApplicationContext getApplicationContext()
    {

        return applicationContextHolder.get();
    }

    public void sessionDestroyed()
    {
        sessionHolder.remove();
    }

       public void removeSession(String attributeName)
    {
        this.getSession().removeAttribute(attributeName);
    }
}

 

阅读更多
个人分类: flex
上一篇session监听
下一篇session Filter
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭