Cookies Sessions with JSP
28 Aug 2012
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |