當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpSession.getAttributeNames方法代碼示例

本文整理匯總了Java中javax.servlet.http.HttpSession.getAttributeNames方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpSession.getAttributeNames方法的具體用法?Java HttpSession.getAttributeNames怎麽用?Java HttpSession.getAttributeNames使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.servlet.http.HttpSession的用法示例。


在下文中一共展示了HttpSession.getAttributeNames方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: chearCache

import javax.servlet.http.HttpSession; //導入方法依賴的package包/類
/**
 * 清除所有session
 * @param session
 * @throws Exception
 */
public static void chearCache(HttpSession session) throws Exception {
	try {
		Enumeration enumeration = session.getAttributeNames();
		while (enumeration.hasMoreElements()) {
			String key = enumeration.nextElement().toString();
			log.info("WebUtil chearCache key:{}", key);
			session.removeAttribute(key);
			log.info("WebUtil removeAttribute key:{}", key);
		}
	} catch (Exception e) {
		log.error("chearCache error {}", e.getMessage());
		e.printStackTrace();
	}
}
 
開發者ID:iunet,項目名稱:iunet-blog,代碼行數:20,代碼來源:WebUtil.java

示例2: clearSession

import javax.servlet.http.HttpSession; //導入方法依賴的package包/類
private void clearSession()
{
	final HttpSession session = getCurrentSession(false);
	if( session != null )
	{
		synchronized( session )
		{
			final String keyPrefix = getKeyPrefix().toString();

			for( Enumeration<?> e = session.getAttributeNames(); e.hasMoreElements(); )
			{
				String name = (String) e.nextElement();
				if( name.startsWith(keyPrefix) )
				{
					session.removeAttribute(name);
				}
			}
		}
	}
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:21,代碼來源:UserSessionServiceImpl.java

示例3: doGet

import javax.servlet.http.HttpSession; //導入方法依賴的package包/類
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {
    resp.setContentType("text/html;charset=UTF-8");
    HttpSession session = req.getSession();
    try (PrintWriter out = resp.getWriter()) {
        out.println("Session ID - " + session.getId() +"\n");
        out.println("ACCS Container - " + System.getenv("APAAS_CONTAINER_NAME") +"\n");
        out.println("Server IP:Port " + InetAddress.getLocalHost().getHostAddress()+":"+req.getServerPort() +"\n");
        out.println("Session Created - " + new Date(session.getCreationTime()) +"\n");
        out.println("Session accessed - " + new Date(session.getLastAccessedTime()) +"\n");
        out.println("Session inactive time - " + session.getMaxInactiveInterval() +"\n");

        
        Enumeration<String> valueNames = session.getAttributeNames();
        if (valueNames.hasMoreElements()) {
            out.println("Session attributes \n");
            while (valueNames.hasMoreElements()) {
                String param = (String) valueNames.nextElement();
                String value = session.getAttribute(param).toString();
                out.println(param + " = " + value);
            }
        }
    }

}
 
開發者ID:abhirockzz,項目名稱:accs-tomcat-redis-springsession,代碼行數:27,代碼來源:AppServlet.java

示例4: retrieveSessionDataFromSession

import javax.servlet.http.HttpSession; //導入方法依賴的package包/類
/**
 * retrieves the session data as map. May be an empty map if the
 * session contains no data.
 * 
 * @param session
 * @return
 */
protected Map<String, Object> retrieveSessionDataFromSession(HttpSession session) {
	Enumeration<String> attributeNames = session.getAttributeNames();
	Map<String, Object> data = new HashMap<>();
	while (attributeNames.hasMoreElements()) {
		String attributeName = attributeNames.nextElement();
		Object value = session.getAttribute(attributeName);
		data.put(attributeName, value);
	}
	return data;
}
 
開發者ID:alecalanis,項目名稱:session-to-cookie,代碼行數:18,代碼來源:SessionToCookieFilter.java

示例5: invalidateCurrentSession

import javax.servlet.http.HttpSession; //導入方法依賴的package包/類
public void invalidateCurrentSession(HttpServletRequest request) {
        /*
        FIXME
        if (!octopusConfig.getIsSessionInvalidatedAtLogin()) {
            // Defined with config that developer don't was logout/session invalidation.
            return;
        }
*/

        /*
        if (SecurityUtils.getSubject() instanceof TwoStepSubject) {
            // Otherwise the principals are cleared from the current subject which isn't something we want :)
            return;
        }
        */
        HttpSession session = request.getSession();

        HashMap<String, Object> content = new HashMap<>();
        Enumeration keys = session.getAttributeNames();

        while (keys.hasMoreElements()) {
            String key = (String) keys.nextElement();
            content.put(key, session.getAttribute(key));
            session.removeAttribute(key);
        }

        SecurityUtils.getSubject().logout();

        session = request.getSession(true);
        for (Map.Entry m : content.entrySet()) {
            session.setAttribute((String) m.getKey(), m.getValue());
        }
        content.clear();
    }
 
開發者ID:atbashEE,項目名稱:atbash-octopus,代碼行數:35,代碼來源:SessionUtil.java

示例6: getAttributeNames

import javax.servlet.http.HttpSession; //導入方法依賴的package包/類
@Override
@SuppressWarnings("unchecked")
protected Enumeration<String> getAttributeNames()
{
  final HttpSession httpSession = _getSession();
  return httpSession == null ? NullEnumeration.instance() : httpSession.getAttributeNames();
}
 
開發者ID:apache,項目名稱:myfaces-trinidad,代碼行數:8,代碼來源:ServletSessionMap.java

示例7: recreateSession

import javax.servlet.http.HttpSession; //導入方法依賴的package包/類
/**
 * Recreating the session
 */
public static void recreateSession(HttpServletRequest request, HttpServletResponse response,
                                   SecureUserDetails user) {
  HttpSession session = request.getSession(false);
  Map<String, Object> sessionAttirbutes = new HashMap<>();
  MemcacheService cacheService = AppFactory.get().getMemcacheService();

  if (session != null) {
    Enumeration sessionAttrEnum = session.getAttributeNames();
    if (sessionAttrEnum != null) {
      while (sessionAttrEnum.hasMoreElements()) {
        Object attribute = sessionAttrEnum.nextElement();
        sessionAttirbutes.put(attribute.toString(), session.getAttribute(attribute.toString()));
      }
    }
    //Deleteing session directly in Redis before invalidating it.
    cacheService.delete(session.getId());
    session.invalidate();
  }

  session = request.getSession(true);
  for (String attributeName : sessionAttirbutes.keySet()) {
    session.setAttribute(attributeName, sessionAttirbutes.get(attributeName));
  }
  //Initialzing the session
  initSession(session, user);
}
 
開發者ID:logistimo,項目名稱:logistimo-web-service,代碼行數:30,代碼來源:SessionMgr.java

示例8: clearSession

import javax.servlet.http.HttpSession; //導入方法依賴的package包/類
/**
 * Removes all attributes stored in session
 * 
 * @param session Session
 */
@SuppressWarnings("unchecked")
private void clearSession(HttpSession session)
{
    Enumeration<String> names = (Enumeration<String>) session.getAttributeNames();
    while (names.hasMoreElements())
    {
        session.removeAttribute(names.nextElement());
    }
}
 
開發者ID:Alfresco,項目名稱:alfresco-remote-api,代碼行數:15,代碼來源:BaseNTLMAuthenticationFilter.java

示例9: sessionDestroyed

import javax.servlet.http.HttpSession; //導入方法依賴的package包/類
/** Notification that a session was invalidated.
 * This method will remove all attrributes from the session.
 * @param se the notification event.
 */
public void sessionDestroyed(HttpSessionEvent se) {
    if (log.isDebugEnabled())
        log.debug("Session Destroyed " + se.getSession(), new Exception("This exception is created merely to record the current stacktrace on a JaffaHttpSessionListener.sessionDestroyed()"));
    HttpSession session = se.getSession();
    Enumeration enumeration = session.getAttributeNames();
    if (enumeration != null) {
        while (enumeration.hasMoreElements()) {
            String attributeName = (String) enumeration.nextElement();
            session.removeAttribute(attributeName);
            if (log.isDebugEnabled())
                log.debug("Removed an existing attribute from the newly acquired Session object: " + attributeName);
        }
    }
}
 
開發者ID:jaffa-projects,項目名稱:jaffa-framework,代碼行數:19,代碼來源:JaffaHttpSessionListener.java


注:本文中的javax.servlet.http.HttpSession.getAttributeNames方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。