Generally, if a user opens a browser, the server will allocate a sessionid, and the session ID can be returned through the session. GETID () function;
However, if the server is shut down, restart the server, and refresh the page, the server will re-allocate a new sessionid;
If you want to retain the original ID, you can save the sessionid in serialization mode.
In CONF/server. XML, add
<Context Path = "/test" docbase = "F: \ Java Web practice \ tomcatproject" reloadable = "true"> <manager classname = "org. apache. catalina. session. persistentmanager "> DEBUG = 0 saveonrestart =" true "maxactivesession ="-1 "minidleswap ="-1 "maxidleswap ="-1 "maxidlebackup ="-1 "<store classname =" org. apache. catalina. session. filestore "directory =" F: \ Java Web practice \ tomcatproject \ Temp "/> </Manager> </context>
Indicates that the serial number is stored in F: \ Java Web practice \ atatproject \ Temp;
The effect is as follows:
1. Open a webpage to output the session ID;
2. Close tomcat, a temporary file will appear in the temp folder;
3. Restart tomcat;
4. Refresh the page, and the session ID remains unchanged;