需要jar文件 放在tomcat lib目录下
1.jedis-2.1.0.jar
2.commons-pool-1.6.jar
3.commons-pool2-2.2.jar
4.tomcat-redis-session-manager-1.2-tomcat-6-1.2.jar
context.xml 文件添加
<Valve className="com.radiadesign.catalina.session.RedisSessionHandlerValve"/>
<Manager className="com.radiadesign.catalina.session.RedisSessionManager"
host="localhost"<!--redis服务器地址-->
port="6379" <!--redis端口-->
database="0"
maxInactiveInterval="60"/><!--过期时间-->
nginx反向代理配置nginx.conf
upstream xy.com {
server localhost:8080;
server localhost:8081;
}
log_format www.xy.com '$remote_addr - $remote_user [$time_local] $request '
'"$status" $body_bytes_sent "$http_referer"'
'"$http_user_agent" "$http_x_forwarded_for"';
server
{
listen 8090;
server_name www.xy.com;
location / {
proxy_connect_timeout 3;
proxy_send_timeout 30;
proxy_read_timeout 30;
proxy_pass http://xy.com;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
access_log logs/localhost.log www.xy.com;
}
实体类放在session中需要实现序列号接口 Serializable
req.getSession().setAttribute("username", "zyc");
System.out.println("username:"+"zyc");
User u = new User("张三",10);
System.out.println(u);
req.getSession().setAttribute("u", u);
中间遇到的报错
1)jedis 版本不合适
Caused by: java.lang.VerifyError: Bad type on operand stack in method
2)缺少commons-pool-1.6.jar文件
java.lang.ClassNotFoundException: org.apache.commons.pool.impl.GenericObjectPool$Config