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

坑爷了!!


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 <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则创建

    /**
     * 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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。