zoukankan      html  css  js  c++  java
  • Session共享

    一、配置nginx.conf

    upstream backserver { 
      ip_hash;
      server 127.0.0.1:8080; 
      server 127.0.0.1:8081;
    }

      server {
        listen 80;
        server_name www.mckz.com;

        #charset koi8-r;

    
    

        #access_log logs/host.access.log main;

    
    

        location / {
          proxy_pass http://backserver;
          index index.html index.html;
          #proxy_connect_timeout 1;
          #proxy_send_timeout 1;
          #proxy_read_timeout 1;
      }

    二、Servlet

    @WebServlet("/NginxServlet")
    public class NginxServlet extends HttpServlet {
        @Override
        protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
            System.out.println("梅川酷子");
            //存值
            String action=req.getParameter("action");
            if(action.equals("setSession")){
                req.getSession().setAttribute("uname","MCKZ");
            }else if(action.equals("getSession")){
                resp.getWriter().write((String)req.getSession().getAttribute("uname"));
            }
        }
    
        @Override
        protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
            doPost(req,resp);
        }
    }

    Spring-Session-Redis

    一、启动Redis

    二、依赖

    SpringBoot+Spring-Session+Redis
                    <!--spring boot 与redis应用基本环境配置 -->
                    <dependency>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-starter-redis</artifactId>
                    </dependency> <!--spring session 与redis应用基本环境配置,需要开启redis后才可以使用,不然启动Spring boot会报错 -->
                    <dependency>
                        <groupId>org.springframework.session</groupId>
                        <artifactId>spring-session-data-redis</artifactId>
                    </dependency>

    三、大配置文件

    server:
      port: 8081
    #redis配置
    spring:
      redis:
        password: redis
  • 相关阅读:
    CentOS 7 下Emacs无法录入中文的问题
    GPS文件中的C1--->P1转换
    centos7上搭建http服务器以及设置目录访问
    在Linux和Windows之间的远程控制的实现
    Emacs中的代码折叠控制
    Fortran程序调试中的“吐核”错误
    CentOS 7.6 系统上添加最新版 NetCDF 4.6.1
    迁移 Emacs 的自定义设置
    CentOS 7系统上制作Clonezilla(再生龙)启动U盘并克隆双系统
    [CentOS 7] TexLive2017中kpsewhich Bug的修复
  • 原文地址:https://www.cnblogs.com/whtt/p/12300559.html
Copyright © 2011-2022 走看看