注:此篇博文是本人看國外官方文檔得來的,建議讀者閱讀原版英文。php
先上一張圖,以下java
圖1web
對圖1的說明:跨域
在HTTP/1.1中,在步驟3執行完成後,connection再也不被關閉,在connection有效的前提細,後面client再也不須要執行步驟1,直接執行步驟二、3就能夠。tomcat
爲了進一步深刻,以下圖2,圖2是我從國外的網上截下來的,建議讀者閱讀原文:服務器
圖2 HttpSession生成後會有個sessionIDcookie
HttpServletRequest中的方法,以下圖3所示: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(); /** * * Returns the current <code>HttpSession</code> * associated with this request or, if there is no * current session and <code>create</code> is true, returns * a new session. * * <p>If <code>create</code> is <code>false</code> * and the request has no valid <code>HttpSession</code>, * this method returns <code>null</code>. * * <p>To make sure the session is properly maintained, * you must call this method before * the response is committed. If the container is using cookies * to maintain session integrity and is asked to create a new session * when the response is committed, an IllegalStateException is thrown. * * * * * @param create <code>true</code> to create * a new session for this request if necessary; * <code>false</code> to return <code>null</code> * if there's no current session * * * @return the <code>HttpSession</code> associated * with this request or <code>null</code> if * <code>create</code> is <code>false</code> * and the request has no valid session * * @see #getSession() * * */ public HttpSession getSession(boolean create);
圖3 獲取HttpSession的方式this
HttpSession中的方法以下圖4所示,銷燬HttpSessionspa
/** * Invalidates this session then unbinds any objects bound * to it. * * @exception IllegalStateException if this method is called on an * already invalidated session */ public void invalidate();
圖4 銷燬HttpSession
client-server model,若是client不發送請求,server不容許發送送數據給client。爲了克服這個困難,開發者能夠使用 XMLHTTPRequest請求服務器——即不斷輪詢服務器,或者WebSocket。
跨域資源共享。英文原版在這裏。