wangzhenhui1991 / Notes

3 stars 0 forks source link

关于request.getSession.getId() 与request.getRequestedSessionId() 取值不同 #25

Open wangzhenhui1991 opened 7 years ago

wangzhenhui1991 commented 7 years ago

stackOverFlow

request.getRequestedSessionId() will return the session id specified by the client (presumably in a cookie). request.getSession().getId() will return the server's session id (if a session does not exist, request.getSession() will create it).

The important difference is that you can't rely on the value returned by request.getRequestedSessionId(), since it may not be valid. From the documentation:

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.

大致上理解 request.getSession().getId(),获得的是服务器根据request保存的session request.getRequestedSessionId(),是返回Client特别指定的SessionId的,不可靠