Skip to content

Instantly share code, notes, and snippets.

@zeroDivisible
Last active December 18, 2015 21:58
Show Gist options
  • Save zeroDivisible/5850752 to your computer and use it in GitHub Desktop.
Save zeroDivisible/5850752 to your computer and use it in GitHub Desktop.
invalidate the session in servlet and redirect the user to he same url, making normal processes to kick in.
// invalidate the session
session.invalidate();
// redirect the user to where they were, so normal login process can kick in
HttpServletResponse response = (HttpServletResponse) servletResponse;
HttpServletRequest request = (HttpServletRequest) servletRequest;
StringBuffer requestUrl = request.getRequestURL();
// by default all GET params from query string will be missing from getRequestURL, let's reconstruct it
if (request.getQueryString() != null) {
requestUrl.append("?").append(request.getQueryString());
}
response.sendRedirect(requestUrl.toString());
return;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment