gpt4 book ai didi

java - 当我只发送重定向时,如何在 Tomcat/Spring Boot 中关闭 JSESSIONID?

转载 作者:行者123 更新时间:2023-11-28 22:24:57 31 4
gpt4 key购买 nike

当我只发送重定向时,如何阻止 Tomcat 发送 JSESSIONID cookie?我根本不访问 .getSession()

@RequestMapping(value = "/*")
public void doUrlRequest(final HttpServletRequest request, HttpServletResponse response) {
...
if (redirect != null) response.sendRedirect(redirect);

控制台

$ curl -i localhost:8080/aaa                                                                                                                                                                               HTTP/1.1 302
Set-Cookie: JSESSIONID=A38FE0B0703F4241414BD8DEF646A2BA; Path=/; HttpOnly
Location: http://localhost:8080/errorNonMobile
Content-Length: 0
Date: Thu, 17 May 2018 19:55:49 GMT

我试过了

request.getServletContext().setSessionTrackingModes(Collections.singleton(SessionTrackingMode.URL));

但是出错了

java.lang.IllegalStateException: The session tracking modes for context [] cannot be set whilst the context is running

我需要另一条路径的 session 。我无法为整个应用程序关闭它。我只想为这个请求处理程序关闭它。

最佳答案

我通过在 Controller 上注释 @Scope 标签来关闭它。

@Controller
//@Scope("session")
@ApiIgnore
public class MyUrlController implements ErrorController {

https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/context/annotation/Scope.html

https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/context/WebApplicationContext.html#SCOPE_SESSION

$ curl -i localhost:8080/aaa
HTTP/1.1 302
Location: http://localhost:8080/errorNonMobile
Content-Length: 0
Date: Thu, 17 May 2018 21:26:25 GMT

关于java - 当我只发送重定向时,如何在 Tomcat/Spring Boot 中关闭 JSESSIONID?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50399842/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com