The example of this article tells the method of reading and writing the Cookie records of Java. Share it for everyone for your reference. The specifics are as follows:
Write cookie, cookie's value can make String, List, MAP, int:
Cookie usernamecookie = new cookie ("username_" + school, enCodedusername); usernamecookie.setmaxage (60 * 60 * 24 * 365); Response.ad DCookie (UsernameCookie); // Set Usericookie-Guess you like courses for mental education Cookie useridCookie = new cookie ("userid_" + school, userid); useridCookie.setmaxage (60 * 60 * 24 * 365); Cookie);Read cookie:
HttpservletRequest Request = (ServletRequestattributes) RequestContextHolder.getRequestttributes ()). GetRequest (); okies = request.getCookies (); // cookies are not empty, then clear if (cookies! = Null) {For (cookie cookies: cookies) {string cookies = cookies = cookies (); // Find the identity of if ("Userid _"+SCHOOLI d)) {userid = cookietemp.getvalue ();}}}It is hoped that this article is helpful to everyone's Java program design.