Implementation of the persistent save of Tomcat implementation session ID

Source: Internet
Author: User
Tags session id java web

In general, if a user opens a browser, the server assigns a SessionID, and the Session.getid () function returns the ID of the session;

However, if once the server is shut down, the server restarts and the page is refreshed, the server will reassign a new SessionID;

If we want to retain the original ID, we can save the SessionID by serialization.

In Conf/server.xml, add in the context, Web project

<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 exists under F:\JAVA WEB practice\tomcatproject\temp;


The effect of the implementation is this:

1. Open a Web page, the purpose of which is to output session ID;

2. To turn off Tomcat, a temporary file appears under the Temp folder;

3. Reboot Tomcat;

4. Refresh the page, the session ID unchanged;


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.