重庆分公司,新征程启航

为企业提供网站建设、域名注册、服务器等服务

tomcat8的session共享实现方案

tomcat8的session共享实现

下载tomcat

版本:apache-tomcat-8.0.53.zip

成都创新互联公司专注于高安网站建设服务及定制,我们拥有丰富的企业做网站经验。 热诚为您提供高安营销型网站建设,高安网站制作、高安网页设计、高安网站官网定制、微信小程序开发服务,打造高安网络公司原创品牌,更为您提供高安网站排名全网营销落地服务。

实现步骤,只需要两步

  1. 两个tomcat的server.xml都增加一样cluster配置
    
        
        
            
            
            
                
            
            
            
        
        
        
        
        
    
  2. 两个tomcat的应用的web.xml下都增加
    比如在:
    /Users/da/Library/Tomcat/apache-tomcat-8.0.53-8081/webapps/ROOT/WEB-INF/web.xml
    增加:
  3. 然后重启两台tomcat即可

新建jsp测试

session.jsp



test2


    SessionID is
    <%=session.getId()%>
    
SessionIP is <%=request.getServerName()%>
SessionPort is <%=request.getServerPort()%> <% out.println("Response from tomcat2"); %>

比如放置在:
/Users/da/Library/Tomcat/apache-tomcat-8.0.53-8082/webapps/ROOT/session.jsp
另一台一样。

访问:
http://localhost:8081/session.jsp
http://localhost:8082/session.jsp

sessionid一致:

SessionID is 6E5D26E07FDE6FB5D01A59F457D64333 
SessionIP is tomcat.chinaunicom.tech 
SessionPort is 80 Response from tomcat1

SessionID is 6E5D26E07FDE6FB5D01A59F457D64333 
SessionIP is tomcat.chinaunicom.tech 
SessionPort is 80 Response from tomcat2

注意事项

  1. 需要使用tomcat8版本(上述测试在8.0.53上通过)。如果需要tomcat7,请告诉我,不是这种配置,我需要修改一下
  2. 不要漏了distributable的配置,漏了session也不能共享
  3. 这种方案只适用于并发量较少的应用,目前可以先用着,明天我再尝试并发量大的复杂一点的方案看行不行

参考官网:
http://localhost:8082/docs/cluster-howto.html
http://tomcat.apache.org/tomcat-8.0-doc/config/cluster.html
翻译:
http://wiki.jikexueyuan.com/project/tomcat/clustering.html


新闻标题:tomcat8的session共享实现方案
URL分享:http://cqcxhl.com/article/ppjpgj.html

其他资讯

在线咨询
服务热线
服务热线:028-86922220
TOP