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/