java Source

            BlogJava :: 首頁 :: 聯(lián)系 :: 聚合  :: 管理
            14 Posts :: 24 Stories :: 8 Comments :: 0 Trackbacks
          package org.lambdasoft.web.support;

          import java.util.ArrayList;
          import java.util.Enumeration;
          import java.util.List;

          import javax.servlet.http.HttpSession;

          import org.apache.struts2.ServletActionContext;
          import org.lambdasoft.web.Enviroment;

          public class SessionSupport {
              
          private SessionSupport() {}
              
              
          /**
               * 獲取當前用戶Session
               * 
               * 
          @return httpSession
               
          */
              
          public final static HttpSession getSession() {
                  
          return ServletActionContext.getRequest().getSession();
              }
              
              @SuppressWarnings(
          "unchecked")
              
          public final static void removeAllSession(HttpSession session) {
                  
          if(session == null)
                      
          return;
                  Enumeration names 
          = session.getAttributeNames();
                  
          if(names == null)
                      
          return;
                  List
          <String> sessionNamesList = new ArrayList<String>();
                  
          while (names.hasMoreElements()) 
                      sessionNamesList.add((String)names.nextElement());
                  
          for (String sessionName : sessionNamesList) {
                      session.removeAttribute(sessionName);
                  }
              }
              
              
          /**
               * 添加或者更新Session票據(jù)信息
               * 
               * 
          @param sessionTick
               
          */
              
          public final static void updateSessionTick(SessionTick<TickInterface> sessionTick) {
                  getSession().removeAttribute(Enviroment.getEnv().getEnv(
          "WEB_SESSION_KEY"));
                  getSession().setAttribute(Enviroment.getEnv().getEnv(
          "WEB_SESSION_KEY"), sessionTick);
              }
              
              
          /**
               * 把用戶票據(jù)加入到Session
               * 
          @param account
               
          */
              
          public final static void addTickToSession(TickInterface account) {
                  SessionTick
          <TickInterface> tick = new SessionTick<TickInterface>();
                  tick.setAccount(account);
                  updateSessionTick(tick);
              }
          }


          /*
           * SessionTick.java
           * Copyright (C) 2009  <JustinLei@gmail.com>
           *
           *        This program is free software; you can redistribute it and/or modify
           *        it under the terms of the GNU General Public License as published by
           *      the Free Software Foundation; either version 2 of the License, or
           *     (at your option) any later version.
           *
           *       This program is distributed in the hope that it will be useful,
           *      but WITHOUT ANY WARRANTY; without even the implied warranty of
           *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
           *        GNU General Public License for more details.
           *
           
          */
          package org.lambdasoft.web.support;

          /**
           * Session Support
           * 
           * 
          @author lei.tang (justinlei@gmail.com)
           * @date 
           * 
          @version
           
          */
          import java.io.Serializable;

          public class SessionTick<extends TickInterface> implements Serializable{
              
          private static final long serialVersionUID = 1L;
              
          private T account = null;
              
              
          public SessionTick() {}
              
              
          public SessionTick(T account) {
                  
          this.account = account;
              }
              
              
          public T getAccount() {
                  
          return account;
              }
              
          public void setAccount(T account) {
                  
          this.account = account;
              }
          }

          package org.lambdasoft.web.support;

          public interface TickInterface {
              Long getId();
          }
          posted on 2009-12-18 16:37 JustinLei 閱讀(1498) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導航:
           
          主站蜘蛛池模板: 从化市| 怀来县| 郑州市| 万盛区| 阳春市| 霍州市| 聂荣县| 称多县| 徐汇区| 沂水县| 阿图什市| 固阳县| 古交市| 桦南县| 濮阳市| 修水县| 白城市| 新晃| 阿拉善右旗| 宾阳县| 江津市| 上蔡县| 克什克腾旗| 临沂市| 任丘市| 张家界市| 周宁县| 奇台县| 磐石市| 昌吉市| 嘉善县| 巴楚县| 榆社县| 得荣县| 彰化县| 偏关县| 界首市| 永丰县| 蒙城县| 金乡县| 武义县|