Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring 从同一浏览器访问API时获取多个会话对象_Spring_Spring Boot_Session_Stateless - Fatal编程技术网

Spring 从同一浏览器访问API时获取多个会话对象

Spring 从同一浏览器访问API时获取多个会话对象,spring,spring-boot,session,stateless,Spring,Spring Boot,Session,Stateless,正如我所了解到的,若您从同一浏览器窗口向服务器请求资源,它将返回相同的会话ID,除非您每次关闭它并从新窗口请求。但在下面的例子中,每当我点击一个示例API时,我都会得到一个新的会话id。这与RESTAPI的无状态行为有关吗?请澄清我的理解 @RequestMapping(path = "/login", method = RequestMethod.POST) public ResponseEntity<Boolean> login(@RequestBody

正如我所了解到的,若您从同一浏览器窗口向服务器请求资源,它将返回相同的会话ID,除非您每次关闭它并从新窗口请求。但在下面的例子中,每当我点击一个示例API时,我都会得到一个新的会话id。这与RESTAPI的无状态行为有关吗?请澄清我的理解

        @RequestMapping(path = "/login", method = RequestMethod.POST)
    public ResponseEntity<Boolean> login(@RequestBody UserCredential credential, HttpServletRequest request) {
        System.out.println("session "+request.getSession().getId());
    }
@RequestMapping(path=“/login”,method=RequestMethod.POST)
公共响应身份登录(@RequestBody UserCredential credential,HttpServletRequest){
System.out.println(“session”+request.getSession().getId());
}

查看您的代码时,您似乎还没有真正登录。 您正在请求登录。 这肯定会在每次打印时创建一个新的会话Id

请按照下面的链接了解如何使用spring登录

链接: