How do I set a cookie value and retrieve the results in a later JSP page?
Created May 4, 2012
Todd Boyer I'll use an example of setting a username as a JSP cookie to use in later pages.
<% String userID = request.getParameter("username"); Cookie theUsername = new Cookie("username", userID); response.addCookie(theUsername); %> Now retrieve the results: <% Cookie theCookie = null; Cookie cookieList[] = request.getCookies(); for(int i = 0; i < cookieList.length; i++) { theCookie = cookieList[i]; if(theCookie.getName().equals("username")) { %> Welcome <%= theCookie.getValue() %>!<% } } %>