Today found a problem, the program in the local run well, packaged to the server, no matter how to add a log, update packaging, and finally there are problems,
Locate the problem step-by-step, and discover that it is a cookie problem.
The service side defines the code that sets the cookie:
public void Setcookie (HttpServletRequest request, httpservletresponse response, String key,string value) {
Cookie Cookie = new Cookie (key, value);//Create a Cookie,cookie name is key
Cookie.setdomain (Request.getservername ());
Cookie.setpath (Request.getcontextpath ());
Set the validity period of the cookie
cookie.setmaxage (constants.cookiemaxage);
Cookie.sethttponly (true);
Adds a cookie object to the response object so that the server outputs the cookie to the client browser
response.addcookie (cookie) when it outputs the contents of the response object;
At first it was suspected that the cookie was not written on the server side, and later through the log, it found that the server was written, but the client could not get it. Used to do
The problem with cookies in web development is basically domain and path issues, but there is no problem with local running and the online environment is fine, I started
Pondering should be another problem, the expiration time problem.
We set the time is 43,200 seconds is 12 hours, but actually see into the first page, did write a cookie, but the expiration time is in the service
12 hours after the time, here is the point of the problem. The test server time is set ahead.
Finally found that the test environment of the machine has indeed been moved, the time was changed to the day earlier, and our cookie expires in 12 hours, even if
Is 12 hours, 43,200 seconds is also past the current time, then modify the test environment time for the current time is good, so that Tomcat does not have to reboot.
To modify the server time:
Note that if you set the HttpOnly property of the cookie to true on the server side, it will also cause the server to write a cookie, and the client will not be able to access the cookie.