Skip to content

Instantly share code, notes, and snippets.

@arttuladhar
Created July 31, 2015 05:07
Show Gist options
  • Save arttuladhar/70c3f0eb0425371c801a to your computer and use it in GitHub Desktop.
Save arttuladhar/70c3f0eb0425371c801a to your computer and use it in GitHub Desktop.
Java cookie session
String user_id = null;
String username = null;
//Check Cookie for the saved session
Cookie[] cookies = request.getCookies();
String _cookieName_id = "user_id";
String _cookieName_user = "user_name";
String _cookie_userid_Value = null;
String _cookie_usernameValue = null;
for (int i=0;i<cookies.length;i++){
Cookie cookie = cookies[i];
if (_cookieName_id.equals(cookie.getName()))
_cookie_userid_Value = cookie.getValue();
if (_cookieName_user.equals(cookie.getName()))
_cookie_usernameValue = cookie.getValue();
}
if (_cookie_userid_Value!= null && _cookie_usernameValue != null){
user_id = _cookie_userid_Value;
username = _cookie_usernameValue;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment