Apache Http Server与Tomcat实现负载均衡和集群
? ??????
?
?
<! DOCTYPE?html?PUBLIC?"-//W3C//DTD?HTML?4.01?Transitional//EN"?"http://www.w3.org/TR/html4/loose.dtd" >
< html >
< head >
< meta? http-equiv ="Content-Type" ?content ="text/html;?charset=UTF-8" >
< title > test1 </ title >
</ head >
< body >
? <%
?? System.out.println( " =========================== " );
%>
</ body >
</ html >
?
< head >
< title > Cluster?App?Test </ title >
</ head >
< body >
Server?Info:
?<%
? out.println(request.getLocalAddr()? + ? " ?:? " ? + ?request.getLocalPort()? + ? " <br> " );
%>
?<%
? out.println( " <br>?ID? " ? + ?session.getId()? + ? " <br> " );
?? // ?如果有新的?Session?属性设置
?? String ?dataName? = ?request.getParameter( " dataName " );
?? if ?(dataName?! = ? null ? && ?dataName.length()? > ? 0 )?{
????? String ?dataValue? = ?request.getParameter( " dataValue " );
???? session.setAttribute(dataName,?dataValue);
? }
? out.print( " <b>Session?列表</b> " );
? Enumeration?e? = ?session.getAttributeNames();
?? while ?(e.hasMoreElements())?{
????? String ?name? = ?( String )?e.nextElement();
????? String ?value? = ?session.getAttribute(name).toString();
???? out.println(name? + ? " ?=? " ? + ?value? + ? " <br> " );
???? System.out.println(name? + ? " ?=? " ? + ?value);
? }
%>
< form? action ="test.jsp" ?method ="POST" >
名称: < input? type =text? size =20? name ="dataName" > ? < br >
值: < input? type =text? size =20? name ="dataValue" > ? < br >
< input? type =submit ></ form >
</ body >
</ html >
< web-app? xmlns:xsi ="http://www.w3.org/2001/XMLSchema-instance" ?xmlns ="http://java.sun.com/xml/ns/javaee" ?xmlns:web ="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" ?xsi:schemaLocation ="http://java.sun.com/xml/ns/javaee?http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" ?id ="WebApp_ID" ?version ="2.5" >
?? < display-name > test </ display-name >
?? < distributable />
?? < welcome-file-list >
???? < welcome-file > index.html </ welcome-file >
???? < welcome-file > index.htm </ welcome-file >
???? < welcome-file > index.jsp </ welcome-file >
???? < welcome-file > default.html </ welcome-file >
???? < welcome-file > default.htm </ welcome-file >
???? < welcome-file > default.jsp </ welcome-file >
?? </ welcome-file-list >
</ web-app >
?
?
?
?
??? 新窗口的请求转发到了 tomcat2 服务器, session 的 id 为 DD9E6C8181653B9BCCF534FC8760B264.tomcat2 ,根据测试结果可以说明,在不发生服务器关闭的情况下,每个 session 会绑定到同一个服务器中,而不会在服务器间发生复制。
?