在请求端点时,如何在控制器级别上创建新的HTTP会话?

问题描述 投票:0回答:1
如何在请求端点请求期间在控制器级别上创建新的活动httpsess?我没有在Springboot中使用任何依赖性...只是Tomcat的Vanilla httpsession。 thnanks

我尝试创建新会议,但总是返回相同的一个会议

java spring-boot httpsession
1个回答
0
投票
会这样吗?

@GetMapping("/createNewSession") public String createNewSession(HttpServletRequest request) { var currentSession = request.getSession(false); String currentSessionId; if (currentSession != null) { currentSessionId = currentSession.getId(); currentSession.invalidate(); } else { currentSessionId = "none"; } // create new session HttpSession newSession = request.getSession(true); return "Old session-ID: " + currentSessionId + ", new session-ID: " + newSession.getId(); }
示例响应:

Old session-ID: 840E96334EF4D11C5D9385E5E99A6BDC, new session-ID: 7AF16EF4DF9107C7D068833EEA8D7F69
    
最新问题
© www.soinside.com 2019 - 2024. All rights reserved.