zoukankan      html  css  js  c++  java
  • 全局Session-GlobalSession

    import javax.servlet.http.HttpServletRequest;  
    import javax.servlet.http.HttpSession;  
      
    import org.springframework.web.context.request.RequestContextHolder;  
    import org.springframework.web.context.request.ServletRequestAttributes;  
      
    /** 
     * 当前session工具类 
     * 
     */  
    public class GlobalSession {  
      
        public static void setSessionAttribute(String arg, Object o) {  
            HttpSession session = getSession();  
            session.setAttribute(arg, o);  
        }  
          
        public static Object getSessionAttribute(String arg) {  
            HttpSession session = getSession();  
            return session.getAttribute(arg);  
        }  
      
        public static void removeSessionAttribute(String arg) {  
            HttpSession session = getSession();  
            if (getSessionAttribute(arg) != null) {  
                session.removeAttribute(arg);  
            }  
        }  
      
        public static void setAttribute(String arg, Object o) {  
            HttpSession session = getHttpSession();  
            session.setAttribute(arg, o);  
        }  
      
      
        public static Object getAttribute(String arg) {  
            HttpSession session = getHttpSession();  
            return session.getAttribute(arg);  
        }  
      
      
        public static void removeAttribute(String arg) {  
            if (getAttribute(arg) != null) {  
                getHttpSession().removeAttribute(arg);  
            }  
        }  
      
          
        public static HttpSession getHttpSession() {  
            HttpServletRequest session = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();  
            return session.getSession();  
        }  
      
          
        public static HttpSession getSession() {  
            HttpServletRequest session = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();  
            return session.getSession();  
        }  
    }  
    
    

    使用方法

    HttpServletRequest   request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
    

    原文地址:https://blog.csdn.net/cbjcry/article/details/70155097

  • 相关阅读:
    文件下载断点续传插件webupload插件
    cocos2dx 2.x 粒子渲染时有黑色粒BUG
    VOIP NAT穿越之SIP信令穿越
    hdu 5086 Revenge of Segment Tree(BestCoder Round #16)
    [并发]线程池技术小白
    调用 COM 对象
    switch-case 执行顺序
    HDELETE
    python and java
    部分查询练习题及答案
  • 原文地址:https://www.cnblogs.com/jpfss/p/9081669.html
Copyright © 2011-2022 走看看