注:此篇博文是本人看国外官方文档得来的,建议读者阅读原版英文。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。
跨域资源共享。英文原版在这里。