本文整理了Java中javax.servlet.http.HttpSession.getAttributeNames()
方法的一些代码示例,展示了HttpSession.getAttributeNames()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpSession.getAttributeNames()
方法的具体详情如下:
包路径:javax.servlet.http.HttpSession
类名称:HttpSession
方法名:getAttributeNames
[英]Returns an Enumeration
of String
objects containing the names of all the objects bound to this session.
[中]返回Enumeration
个String
对象,其中包含绑定到此会话的所有对象的名称。
代码示例来源:origin: perwendel/spark
/**
* @return an <code>Enumeration</code> of <code>String</code> objects
* containing the names of all the objects bound to this session.
*/
public Set<String> attributes() {
TreeSet<String> attributes = new TreeSet<>();
Enumeration<String> enumeration = session.getAttributeNames();
while (enumeration.hasMoreElements()) {
attributes.add(enumeration.nextElement());
}
return attributes;
}
代码示例来源:origin: thymeleaf/thymeleaf
@Override
public boolean isEmpty() {
if (this.session == null) {
return true;
}
final Enumeration<String> attributeNames = this.session.getAttributeNames();
return !attributeNames.hasMoreElements();
}
代码示例来源:origin: Atmosphere/atmosphere
public FakeHttpSession copyAttributes(HttpSession httpSession) {
Enumeration<String> e = httpSession.getAttributeNames();
String k;
while (e.hasMoreElements()) {
k = e.nextElement();
if (k == null) continue;
Object o = httpSession.getAttribute(k);
if (o == null) continue;
attributes.put(k, o);
}
return this;
}
代码示例来源:origin: spring-projects/spring-session
@Override
public void doFilter(HttpServletRequest wrappedRequest) {
assertThat(wrappedRequest.getSession().getAttribute(ATTR))
.isEqualTo(VALUE);
assertThat(
Collections.list(wrappedRequest.getSession().getAttributeNames()))
.containsOnly(ATTR);
}
});
代码示例来源:origin: nutzam/nutz
public static String dumpSessionAttributes(HttpSession session) {
StringBuilder sb = new StringBuilder();
Enumeration<?> en = session.getAttributeNames();
while (en.hasMoreElements()) {
String name = (String) en.nextElement();
sb.append("[" + name + "]: " + session.getAttribute(name) + '\n');
}
return sb.toString();
}
代码示例来源:origin: Red5/red5-server
/** {@inheritDoc} */
public void removeAttributes() {
// synchronize to prevent parallel modifications
synchronized (session) {
final Enumeration<String> names = session.getAttributeNames();
while (names.hasMoreElements()) {
session.removeAttribute(names.nextElement());
}
}
}
代码示例来源:origin: org.freemarker/freemarker
public boolean isEmpty()
throws TemplateModelException {
checkSessionExistence();
return session == null || !session.getAttributeNames().hasMoreElements();
}
}
代码示例来源:origin: spring-projects/spring-session
@Override
public void doFilter(HttpServletRequest wrappedRequest) {
wrappedRequest.getSession().setAttribute(ATTR, VALUE);
assertThat(wrappedRequest.getSession().getAttribute(ATTR))
.isEqualTo(VALUE);
assertThat(
Collections.list(wrappedRequest.getSession().getAttributeNames()))
.containsOnly(ATTR);
}
});
代码示例来源:origin: Red5/red5-server
/** {@inheritDoc} */
public Map<String, Object> getAttributes() {
final Map<String, Object> result = new HashMap<String, Object>();
// Synchronize to prevent parallel modifications
synchronized (session) {
final Enumeration<String> names = session.getAttributeNames();
while (names.hasMoreElements()) {
final String name = names.nextElement();
result.put(name, session.getAttribute(name));
}
}
return Collections.unmodifiableMap(result);
}
代码示例来源:origin: thymeleaf/thymeleaf
@Override
public int size() {
if (this.session == null) {
return 0;
}
int size = 0;
final Enumeration<String> attributeNames = this.session.getAttributeNames();
while (attributeNames.hasMoreElements()) {
attributeNames.nextElement();
size++;
}
return size;
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void handleAndCompleteSession() throws Exception {
HandlerMethod handlerMethod = handlerMethod("handleAndCompleteSession", SessionStatus.class);
handlerAdapter.handle(request, response, handlerMethod);
assertFalse(request.getSession().getAttributeNames().hasMoreElements());
}
代码示例来源:origin: javamelody/javamelody
session.getLastAccessedTime() + session.getMaxInactiveInterval() * 1000L);
final List<String> attributeNames = Collections.list(session.getAttributeNames());
attributeCount = attributeNames.size();
serializable = computeSerializable(session, attributeNames);
final Object countryCode = session.getAttribute(SessionListener.SESSION_COUNTRY_KEY);
if (countryCode == null) {
country = null;
final Object addr = session.getAttribute(SessionListener.SESSION_REMOTE_ADDR);
if (addr == null) {
remoteAddr = null;
Object user = session.getAttribute(SessionListener.SESSION_REMOTE_USER);
if (user == null) {
代码示例来源:origin: thymeleaf/thymeleaf
@Override
public Collection<Object> values() {
if (this.session == null) {
return Collections.emptySet();
}
final List<Object> values = new ArrayList<Object>(5);
final Enumeration<String> attributeNames = this.session.getAttributeNames();
while (attributeNames.hasMoreElements()) {
values.add(this.session.getAttribute(attributeNames.nextElement()));
}
return values;
}
代码示例来源:origin: Red5/red5-server
/** {@inheritDoc} */
public Set<String> getAttributeNames() {
final Set<String> result = new HashSet<String>();
// Synchronize to prevent parallel modifications
synchronized (session) {
final Enumeration<String> names = session.getAttributeNames();
while (names.hasMoreElements()) {
result.add(names.nextElement());
}
}
return Collections.unmodifiableSet(result);
}
代码示例来源:origin: psi-probe/psi-probe
for (String name : Collections.list(httpSession.getAttributeNames())) {
Object obj = httpSession.getAttribute(name);
sessionSerializable = sessionSerializable && obj instanceof Serializable;
(String) httpSession.getAttribute(ApplicationSession.LAST_ACCESSED_BY_IP);
if (lastAccessedIp != null) {
sbean.setLastAccessedIp(lastAccessedIp);
sbean.setLastAccessedIpLocale(
(Locale) httpSession.getAttribute(ApplicationSession.LAST_ACCESSED_LOCALE));
代码示例来源:origin: looly/hutool
/**
* 将Session中的值放入模板上下文
* @param context 模板上下文
* @param session Session
* @return VelocityContext
*/
public static VelocityContext parseSession(VelocityContext context, javax.servlet.http.HttpSession session) {
if (null != session) {
final Enumeration<String> sessionAttrs = session.getAttributeNames();
if (sessionAttrs != null) {
String attrName = null;
while (sessionAttrs.hasMoreElements()) {
attrName = sessionAttrs.nextElement();
context.put(attrName, session.getAttribute(attrName));
}
}
}
return context;
}
代码示例来源:origin: thymeleaf/thymeleaf
@Override
public Set<String> keySet() {
if (this.session == null) {
return Collections.emptySet();
}
final Set<String> keySet = new LinkedHashSet<String>(5);
final Enumeration<String> attributeNames = this.session.getAttributeNames();
while (attributeNames.hasMoreElements()) {
keySet.add(attributeNames.nextElement());
}
return keySet;
}
代码示例来源:origin: pac4j/jax-rs-pac4j
@Override
public boolean renewSession(JaxRsContext context) {
final HttpSession session = getHttpSession(context);
final Map<String, Object> attributes = new HashMap<>();
Collections.list(session.getAttributeNames()).forEach(k -> attributes.put(k, session.getAttribute(k)));
session.invalidate();
// let's recreate the session from zero, the previous becomes
// generally unusable depending on the servlet implementation
final HttpSession newSession = getHttpSession(context);
attributes.forEach(newSession::setAttribute);
return true;
}
代码示例来源:origin: looly/hutool
/**
* 将Session中的值放入模板上下文
* @param context 模板上下文
* @param session Session
* @return VelocityContext
*/
public static VelocityContext parseSession(VelocityContext context, javax.servlet.http.HttpSession session) {
if (null != session) {
final Enumeration<String> sessionAttrs = session.getAttributeNames();
if (sessionAttrs != null) {
String attrName = null;
while (sessionAttrs.hasMoreElements()) {
attrName = sessionAttrs.nextElement();
context.put(attrName, session.getAttribute(attrName));
}
}
}
return context;
}
代码示例来源:origin: apache/shiro
public Collection<Object> getAttributeKeys() throws InvalidSessionException {
try {
Enumeration namesEnum = httpSession.getAttributeNames();
Collection<Object> keys = null;
if (namesEnum != null) {
keys = new ArrayList<Object>();
while (namesEnum.hasMoreElements()) {
keys.add(namesEnum.nextElement());
}
}
return keys;
} catch (Exception e) {
throw new InvalidSessionException(e);
}
}
内容来源于网络,如有侵权,请联系作者删除!