1. Introduction to Cookies
cookie: Data stored on the client to maintain session state.
//create a cookie Cookie cookie = new Cookie(name , value); //pass the cookie to the client response.addCookie(cookie );
The client will return a cookie every time it visits, and the server will traverse the cookie code
Cookie[] cookies = request.getCookies(); if(null != cookies && cookies.length > 0){ for(Cookie cookie : cookies){ // Find the target cookie by traversing } }
Removal of cookies
//1. When the parameter is negative, the browser writes the cookie into the browser memory (the default is memory storage) //2. When set to 0, the browser will remove the cookie //3. When it is a positive number, it will be persisted to the hard disk and deleted after the specified time cookie.setMaxAge(0); //Write the cookie back to the browser and notify the browser to delete the cookie response.addCookie(cookie);