关闭

session管理

351人阅读 评论(0) 收藏 举报

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);
    }
}

 

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:359355次
    • 积分:4649
    • 等级:
    • 排名:第6260名
    • 原创:152篇
    • 转载:28篇
    • 译文:1篇
    • 评论:25条
    文章分类
    最新评论