据我所知,如果你从同一个浏览器窗口向服务器请求一个资源,它会返回相同的会话ID,除非你每次都关闭它并从一个新窗口请求。但是在下面的例子中,每次我点击一个示例API,我都会得到一个新的会话id。是不是和REST API的无状态行为有关?请澄清我的理解。
@RequestMapping(path = "/login", method = RequestMethod.POST)
public ResponseEntity<Boolean> login(@RequestBody UserCredential credential, HttpServletRequest request) {
System.out.println("session "+request.getSession().getId());
}
发布于 2019-09-16 09:55:26
查看您的代码看起来您实际上还没有登录。您正在请求登录。这肯定会在您每次打印它时创建一个新的会话Id。
请点击下面的链接,了解spring是如何登录的。
链接:https://dzone.com/articles/spring-mvc-example-for-user-registration-and-login-1
https://stackoverflow.com/questions/57952623
复制相似问题