memcached tomcat session 共享
阿新 • • 發佈:2019-02-11
1.到tomcat的安裝目錄lib中,加入:
3:編輯session.jsp 進行測試是否session共享
memcached-2.6.jar
javolution-5.4.3.1.jar
memcached-session-manager-1.5.1.jar
memcached-session-manager-tc7-1.5.1.jar
msm-javolution-serializer-1.5.1.jar
msm-kryo-serializer-1.5.1.jar
msm-xstream-serializer-1.5.1.jar
下載地址:http://download.csdn.net/detail/zxbcome/9634721
2.配置tomcat. 在%TOMCAT_HOME%\config\context.xml 檔案中加入】
<Context> <!-- Default set of monitored resources --> <WatchedResource>WEB-INF/web.xml</WatchedResource> <!-- Uncomment this to disable session persistence across Tomcat restarts --> <!-- <Manager pathname="" /> --> <!-- Uncomment this to enable Comet connection tacking (provides events on session expiration as well as webapp lifecycle) --> <!-- <Valve className="org.apache.catalina.valves.CometConnectionManagerValve" /> --> <Manager className="de.javakaffee.web.msm.MemcachedBackupSessionManager" memcachedNodes="n1:192.168.1.41:11211" requestUriIgnorePattern=".*\.(ico|png|gif|jpg|css|js)$" sessionBackupAsync="false" sessionBackupTimeout="1800000" copyCollectionsForSerialization="false" transcoderFactoryClass="de.javakaffee.web.msm.serializer.javolution.JavolutionTranscoderFactory"/> </Context>
3:編輯session.jsp 進行測試是否session共享
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>My JSP 'session.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> </head> <body> <% System.out.println(session.getId()); out.println("<br> This is (TOMCAT1|TOMCAT2), SESSION ID:" + session.getId()+"<br>"); %> </body> </html>