您现在的位置是:主页 > news > 筑建网/seo短视频网页入口引流

筑建网/seo短视频网页入口引流

admin2025/5/31 4:04:48news

简介筑建网,seo短视频网页入口引流,高级网站开发工程师,专家网络公司排名有几种办法:1.扩展指定server利用Servlet容器提供的插件功能,自定义HttpSession的创建和管理策略,并通过配置的方式替换掉默认的策略。缺点:耦合Tomcat/Jetty等Servlet容器,不能随意更换容器。2.利用Filter利用HttpSer…

筑建网,seo短视频网页入口引流,高级网站开发工程师,专家网络公司排名有几种办法:1.扩展指定server利用Servlet容器提供的插件功能,自定义HttpSession的创建和管理策略,并通过配置的方式替换掉默认的策略。缺点:耦合Tomcat/Jetty等Servlet容器,不能随意更换容器。2.利用Filter利用HttpSer…

有几种办法:

1.扩展指定server

利用Servlet容器提供的插件功能,自定义HttpSession的创建和管理策略,并通过配置的方式替换掉默认的策略。缺点:耦合Tomcat/Jetty等Servlet容器,不能随意更换容器。

2.利用Filter

利用HttpServletRequestWrapper,实现自己的 getSession()方法,接管创建和管理Session数据的工作。spring-session就是通过这样的思路实现的。

3 利用spring session

Spring Boot中spring session支持方式:

JDBC、MongoDB、Redis、Hazelcast、HashMap

一、引入maven依赖

UTF-8

UTF-8

1.8

org.springframework.boot

spring-boot-starter-data-redis

org.springframework.session

spring-session-data-redis

org.springframework.boot

spring-boot-starter-web

二、配置application.properties

server.port=8080

spring.redis.host=localhost

spring.redis.port=6379

# spring session使用存储类型

spring.session.store-type=redis

spirngboot默认就是使用redis方式,如果不想用可以填none。、

三、在启动类中加入@EnableRedisHttpSession  注解

48304ba5e6f9fe08f3fa1abda7d326ab.png

package com.shyroke;

import org.springframework.boot.SpringApplication;

import org.springframework.boot.autoconfigure.SpringBootApplication;

import org.springframework.cache.annotation.EnableCaching;

import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession;

@EnableCaching

@EnableRedisHttpSession

@SpringBootApplication

public class SpringbootSessionApplication {

public static void main(String[] args) {

SpringApplication.run(SpringbootSessionApplication.class, args);

}

}

48304ba5e6f9fe08f3fa1abda7d326ab.png

四、编写控制器

48304ba5e6f9fe08f3fa1abda7d326ab.png

package com.shyroke.controller;

import java.util.HashMap;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import org.springframework.http.HttpRequest;

import org.springframework.stereotype.Controller;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.ResponseBody;

@Controller

@RequestMapping(value = "/")

public class IndexController {

@ResponseBody

@RequestMapping(value = "/session")

public Map getSession(HttpServletRequest request) {

request.getSession().setAttribute("username", "admin");

Map map = new HashMap();

map.put("sessionId", request.getSession().getId());

return map;

}

@ResponseBody

@RequestMapping(value = "/get")

public String get(HttpServletRequest request) {

String userName = (String) request.getSession().getAttribute("username");

return userName;

}

}

48304ba5e6f9fe08f3fa1abda7d326ab.png

五、测试

先输入http://localhost:8080/session,在session中设置一个值

8a3a431c953ac8fe79cc982ca630426e.png

http://localhost:8080/get,获取session中的值

4796890dc24131213de2871ad23e947e.png

复制这个工程,application.properties中的server.port=8081,然后访问“http://localhost:8081/get”,如下获取到了另一个工程中设置的session的值。

d2b8ea394d570a09d0eb58e30e20a111.png