Configure Tomcat to persist the session to MySQL

Source: Internet
Author: User

First, in the Conf/context.xml file, add the following configuration to the root node:

<manager classname= "Org.apache.catalina.session.PersistentManager"        maxactivesessions= "-1"       minidleswap= "-1"        maxidleswap= "-1"       maxidlebackup= "-1" >       <store classname= "Org.apache.catalina.session.JDBCStore"          drivername= "Com.mysql.jdbc.Driver"         connectionurl= "JDBC: Mysql://2.2.2.76:3306/test_session?user=user&amp;password=password "         sessiontable= "Sessions"         sessionidcol= "session_id"  sessiondatacol= "Session_data"         sessionvalidcol= "valid_ Session " sessionmaxinactivecol=" Max_inactive "         Sessionlastaccessedcol= "Last_access" &Nbsp;sessionappcol= "App_name"  checkinterval= " />    </Manager>" 

Second, copy the Mysql-connector-java-5.1.34-bin.jar to the Tomcat Lib directory, or you will not find the driver!

In the third step, execute the following script in the database test_session to create a table to store the session data, complete

CREATE TABLE Sessions (session_id VARCHAR) not null PRIMARY KEY, valid_session CHAR (1) is not NULL, Max_inac tive INT NOT NULL, last_access BIGINT NOT NULL, app_name VARCHAR (255), Session_data Mediumblob, KEY Kapp_name (app_name));


If you need to adjust the relevant parameters, you can refer to the Tomcat documentation: http://tomcat.apache.org/tomcat-6.0-doc/config/manager.html

Configure Tomcat to persist the session to MySQL

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.