本文整理汇总了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();
}
}
示例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);
}
}
}
}
}
示例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);
}
}
}
}
示例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;
}
示例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();
}
示例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();
}
示例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);
}
示例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());
}
}
示例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);
}
}
}