第五章. 集群测试
1. tomcat7_a和tomcat7_b的cluster工程中分别添加测试文件:testCluster.jsp
<%@ page contentType="text/html; charset=GBK" %> <%@ page import="Java.util.*" %> <html><head><title>Cluster Test</title></head> <body> <% //HttpSession session = request.getSession(true); System.out.println(session.getId()); out.println("<br> SESSION ID:" + session.getId()+"<br>"); // 如果有新的请求,则添加session属性 String name = request.getParameter("name"); if (name != null && name.length() > 0) { String value = request.getParameter("value"); session.setAttribute(name, value); } out.print("<b>Session List:</b>"); Enumeration<String> names = session.getAttributeNames(); while (names.hasMoreElements()) { String sname = names.nextElement(); String value = session.getAttribute(sname).toString(); out.println( sname + " = " + value+"<br>"); System.out.println( sname + " = " + value); } %> <form action="testCluster.jsp" method="post"> 名称:<input type=text size=20 name="name"> <br> 值:<input type=text size=20 name="value"> <br> <input type=submit value="提交"> </form> </body> </html>2. 启动tomcat7_a,启动完毕后,启动tomcat7_b
3. 进入:8081/cluster/testCluster.jsp 对应tomcat7_a(8081),登录几次,可看到
4. 另外打开一个浏览器,进入:8082/cluster/testCluster.jsp对应tomcat7_b(8082),登录name:tomcat_b,value:b value可看到
5. 刷新tomcat7_a(8081)相关页面,可以看到从tomcat7_b提交的值session同步过来了,说明集群成功。