1. Download and install Tomcat. Tomcat 6.0.24 is used here;
2. Modify the conf/server. xml file and open and save the comments before and after <cluster classname = "org. Apache. Catalina. Ha. tcp. simpletcpcluster"/>;
3. create a web app, here to simply use the Tomcat built-in examples web app (webapps/examples), modify the WEB-INF/web. XML file. After adding the <display-Name> Servlet and jsp examples </display-Name> node, <distributable/> indicates that the application copies the session with the cluster server;
4. create a test under the examples directory. JSP file, used to test that the session used by two Tomcat servers in the cluster is the same session, and when one Tomcat modifies the value in the session, the second Tomcat will also be updated;CodeAs follows:
<HTML> <br/> <pead> <br/> <title> </title> <br/> </pead> <br/> <body> <br/> <% <br/> string mydata = request. getparameter ("mydata"); <br/> If (mydata! = NULL & mydata. Length ()! = 0) {<br/> session. setattribute ("mydata", mydata); <br/>}</P> <p> out. println ("request. getlocaladdr (): "+ request. getlocaladdr (); <br/> out. println ("<br/>"); <br/> out. println ("request. getlocalport (): "+ request. getlocalport (); <br/> out. println ("<br/>"); <br/> out. println ("session ID:" + session. GETID (); <br/> out. println ("<br/>"); </P> <p> out. println ("mydata:" + session. getattribute ("mydata ")); <br/> %> <br/> <form> <br/> <input type = text size = 20 name = "mydata"> <br/> <br /> <input type = submit> <br/> </form> <br/> </body> <br/> </ptml>
5. copy the complete Tomcat directory (named tomcat1) to another place (named tomcat2) and modify tomcat2/CONF/server. port in the XML file (8080-> 9080,8009-> 9009,8443-> 9443)
6. start tomcat1 and tomcat2, and then access http: // localhost: 8080/examples/test. JSP and http: // localhost: 9080/examples/test. JSP, you will find that the session ID used is the same session ID, modify the value of one of them, and change the value of the other Tomcat session.