session.getId()和request.getRequestedSessionId()不一樣?。?!

坑爺了!!


request.getSession().getId()將返回服務器的會話ID(如果會話不存在,request.getSession()將創(chuàng)建它)。
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 <code>null</code>.
     *
     * @return a <code>String</code> specifying the session ID, or
     *         <code>null</code> if the request did not specify a session ID
     * @see #isRequestedSessionIdValid
     */
    public String getRequestedSessionId();

getSession:沒有Session則創(chuàng)建

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

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

最后編輯于
?著作權歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

友情鏈接更多精彩內(nèi)容