The Cookie is used to save user information in the project. I didn't pay too much attention to it before. Today, how to set cookies is invalid, and the breakpoint has been followed countless times, and no problem is found, the code for sending the Cookie is executed, but the response cannot find where the Cookie is sent. The HttpWatch command also reads the Cookie multiple times, and the Response Header does not send the Cookie information.
I feel that my knowledge is too scarce and I have no way to start with any problems. This is nothing to do, with a try attitude to response. after the sendRedirect () Statement is moved to sending the Cookie, the miracle happens inadvertently. Then, I suddenly realized that the Cookie setting should be before the redirection, although no relevant information was found, but at least remember this conclusion first. Otherwise, you will have to take a detour. Today, you have to remember that it takes too much valuable time.
This should be avoided. The program will not report errors, but it will not get the expected results, which is crazy. Be very careful when writing code later. Mistakes are inevitable in the beginner's stage. Only when you see more can you be knowledgeable. More importantly, you can grow up only after constant accumulation. This process may be very painful, but it may also be painful and happy.
If ("true ". equals (request. getParameter ("auto_login") {Cookie cookie = new Cookie ("autoLogin", bean. getUsername () + "> <" + Encrypt. MD5 (bean. getPassword (); cookie. setMaxAge (3600*24*30); cookie. setPath ("/"); response. addCookie (cookie);} // the user name and password are correct. You can log on to the request. getSession (). setAttribute ("userbean", bean); response. sendRedirect (request. getContextPath () + "/");