memcached tomcat session 共享

来源:互联网 发布:免费远程控制软件 编辑:程序博客网 时间:2024/05/19 21:16
1.到tomcat的安装目录lib中,加入:

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>  


0 0
原创粉丝点击