gpt4 book ai didi

java - request.getSession().getId() 与 request.getRequestedSessionId()

转载 作者:行者123 更新时间:2023-11-29 09:52:20 33 4
gpt4 key购买 nike

request.getSession().getId()request.getRequestedSessionId() 有什么区别?它们是否都返回相同的东西,即 session ID?

谢谢

最佳答案

request.getRequestedSessionId() 将返回客户端指定的 session ID(大概在 cookie 中)。 request.getSession().getId() 将返回服务器的 session ID(如果 session 不存在,request.getSession() 将创建它)。

重要的区别是您不能依赖 request.getRequestedSessionId() 返回的值,因为它可能无效。来自文档:

Returns the session ID specified by the client. This may not be the same as the ID of the current valid session for this request. If the client did not specify a session ID, this method returns null.

关于java - request.getSession().getId() 与 request.getRequestedSessionId(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38797066/

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