当前位置: 首页>>代码示例>>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;未经允许,请勿转载。