session.getId()和request.getRequestedSessionId()不一样!!!

坑爷了!!


session.getId()和request.getRequestedSessionId()不一样!!!_第1张图片

request.getSession().getId()将返回服务器的会话ID(如果会话不存在,request.getSession()将创建它)。
request.getRequestedSessionId()是从cookie中获取的~~ ,如果浏览器没有cookie,或者客户端没有指定cookie,它就是空的。
真的太不靠谱了~~
mmp

getRequestedSessionId:没有指定,则为null~~

    /**
     * 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.
     *
     * @return a String specifying the session ID, or
     *         null if the request did not specify a session ID
     * @see #isRequestedSessionIdValid
     */
    public String getRequestedSessionId();

getSession:没有Session则创建

    /**
     * Returns the current session associated with this request, or if the
     * request does not have a session, creates one.
     *
     * @return the HttpSession associated with this request
     * @see #getSession(boolean)
     */
    public HttpSession getSession();

https://stackoverflow.com/questions/38797066/request-getsession-getid-vs-request-getrequestedsessionid

你可能感兴趣的