搭建Tomcat+session共享,用Redis保存session
来源:互联网 发布:oppo手机自动开启数据 编辑:程序博客网 时间:2024/06/06 02:26
环境: Win7,Tomcat7
1. 下载
redis : https://github.com/MSOpenTech/redis/releases
tomcat-redis-session-manager : https://github.com/jcoleman/tomcat-redis-session-manager
2. Tomcat添加Jar包
1. tomcat-redis-session-manager.jar : 下载源码编译
2. jedis,commons-pool2,tomcat-juli : tomcat-redis-session-manager.jar依赖包(tomcat/lib里没有)
3. 添加到tomcat/lib目录
## 可以使用http://download.csdn.net/download/u010379996/9792528
3. 配置Tomcat:context.xml
<Valve className="com.orangefunction.tomcat.redissessions.RedisSessionHandlerValve" />
<Manager className="com.orangefunction.tomcat.redissessions.RedisSessionManager"
host="127.0.0.1"
port="6379"
database="0"
maxInactiveInterval="1800" />
4. 测试
I. 创建session.jsp:
<%@page import="java.io.PrintWriter"%>
<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>session</title>
</head>
<body>
<%
Object data = request.getSession().getAttribute("data");
PrintWriter writer = response.getWriter();
if(data==null){
request.getSession().setAttribute("data", "redis!");
writer.write("not session!");
} else {
writer.write(data.toString());
}
writer.flush();
writer.close();
%>
</body>
</html>
II.
a. 启动redis,tomcat,访问session.jsp
b. 停止tomcat,再访问session.jsp
c. 查看redis里的数据,看session是否存在
1. 下载
redis : https://github.com/MSOpenTech/redis/releases
tomcat-redis-session-manager : https://github.com/jcoleman/tomcat-redis-session-manager
2. Tomcat添加Jar包
1. tomcat-redis-session-manager.jar : 下载源码编译
2. jedis,commons-pool2,tomcat-juli : tomcat-redis-session-manager.jar依赖包(tomcat/lib里没有)
3. 添加到tomcat/lib目录
## 可以使用http://download.csdn.net/download/u010379996/9792528
3. 配置Tomcat:context.xml
<Valve className="com.orangefunction.tomcat.redissessions.RedisSessionHandlerValve" />
<Manager className="com.orangefunction.tomcat.redissessions.RedisSessionManager"
host="127.0.0.1"
port="6379"
database="0"
maxInactiveInterval="1800" />
4. 测试
I. 创建session.jsp:
<%@page import="java.io.PrintWriter"%>
<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>session</title>
</head>
<body>
<%
Object data = request.getSession().getAttribute("data");
PrintWriter writer = response.getWriter();
if(data==null){
request.getSession().setAttribute("data", "redis!");
writer.write("not session!");
} else {
writer.write(data.toString());
}
writer.flush();
writer.close();
%>
</body>
</html>
II.
a. 启动redis,tomcat,访问session.jsp
b. 停止tomcat,再访问session.jsp
c. 查看redis里的数据,看session是否存在
0 0
- 搭建Tomcat+session共享,用Redis保存session
- Nginx+Tomcat+Redis搭建共享SESSION集群
- tomcat redis session 共享
- tomcat-redis-session共享
- Nginx+Tomcat搭建集群,Spring Session+Redis实现Session共享
- Nginx+Tomcat搭建集群,Spring Session+Redis实现Session共享
- Nginx+Tomcat搭建集群,Spring Session+Redis实现Session共享
- Nginx+Tomcat搭建集群,Spring Session+Redis实现Session共享
- 用Redis存储Tomcat集群的Session实现session共享
- redis+tomcat session共享实践
- tomcat+redis+nginx session共享
- tomcat+redis实现session共享
- tomcat + redis 实现session共享
- Redis解决Tomcat共享Session
- Tomcat-Session共享实现-Redis
- Nginx Redis tomcat session共享
- nginx-tomcat-redis共享session
- tomcat+nginx+redis实现均衡负载、session共享---让Tomcat把会话Session保存到Redis数据库。
- 一个关于scrollme.js 的愚蠢的错误
- 性能优化:内存:MAT
- Java JDBC数据库链接
- 图片保存和删除
- 报表工具的二次革命-集算报表
- 搭建Tomcat+session共享,用Redis保存session
- appium(七)测试webview
- 使用IDEA和gradle搭建Spring MVC和MyBatis开发环境
- web js jquery css 倒影
- sqoop常用命令整理
- SOJ 1041
- 最长公共子序列
- 自定义PulltoRefresh刷新的样式 以及集成PulltoRefresh
- 三轴加速度传感器BMA250解读