Skip to content

Instantly share code, notes, and snippets.

@gakuzzzz
Created May 11, 2011 16:38
Show Gist options
  • Save gakuzzzz/966827 to your computer and use it in GitHub Desktop.
Save gakuzzzz/966827 to your computer and use it in GitHub Desktop.
Session作り直し
final Map<String, Object> attributes = new HashMap<String, Object>();
final Enumeration<String> names = (Enumeration<String>) session.getAttributeNames(); // SuppressWarnings!
for (;names.hasMoreElements();) {
final String key = names.nextElement();
final Object value = session.getAttribute(key);
attributes.put(key, value);
}
session.invalidate();
final HttpSession newSession = httpServletRequest.getSession(true);
for (final Entry<String, Object> entry : attributes.entrySet()) {
newSession.setAttribute(entry.getKey(), entry.getValue());
}
newSession.setAttribute("username", loginForm.username);
newSession.setAttribute("password", loginForm.password);
newSession.setAttribute("path", loginRedirectContextDto.redirectPath);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment