<div class="output_wrapper" id="output_wrapper_id" style="font-size: 15px; color: rgb(62, 62, 62); line-height: 1.8; word-spacing: 2px; letter-spacing: 2px; font-family: 'Helvetica Neue', Helvetica, 'Hiragino Sans GB', 'Microsoft YaHei', Arial, sans-serif; background-image: linear-gradient(90deg, rgba(50, 0, 0, 0.05) 3%, rgba(0, 0, 0, 0) 3%), linear-gradient(360deg, rgba(50, 0, 0, 0.05) 3%, rgba(0, 0, 0, 0) 3%); background-size: 20px 20px; background-position: center center;"><h3 id="h1ajax" style="color: inherit; line-height: inherit; padding: 0px; margin: 1.6em 0px; font-weight: bold; border-bottom: 2px solid rgb(239, 112, 96); font-size: 1.3em;"><span style="font-size: inherit; line-height: inherit; margin: 0px; display: inline-block; font-weight: normal; background: rgb(239, 112, 96); color: rgb(255, 255, 255); padding: 3px 10px 1px; border-top-right-radius: 3px; border-top-left-radius: 3px; margin-right: 3px;">1.Ajax</span><span style="display: inline-block; vertical-align: bottom; border-bottom: 36px solid rgb(239, 235, 233); border-right: 20px solid transparent;"> </span></h3> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">AJAX = Asynchronous JavaScript and XML(異步 JavaScript 和 XML)。</p> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">Ajax 的原理簡單來講經過 XmlHttpRequest 對象來向服務器發異步請求,從服務器得到數據,而後用 Javascript 來操做 DOM 而更新頁面。這其中最關鍵的一步就是從服務器得到請求數據。</p> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">XmlHttpRequest 是 ajax 的核心機制,它是在 IE5 中首先引入的,是一種支持異步請求的技術。簡單的說,也就是 Javascript 能夠及時向服務器提出請求和處理響應,而不阻塞用戶。達到無刷新的效果</p> <figure style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px;"><img src="https://upload-images.jianshu.io/upload_images/11243907-fe16c2febe6b3660.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png" title="image.png" style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; display: block; margin: 0px auto; max-width: 100%;"><figcaption style="line-height: inherit; margin: 0px; padding: 0px; margin-top: 10px; text-align: center; color: rgb(153, 153, 153); font-size: 0.7em;">image.png</figcaption></figure> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;"></p> <h3 id="h2jquery" style="color: inherit; line-height: inherit; padding: 0px; margin: 1.6em 0px; font-weight: bold; border-bottom: 2px solid rgb(239, 112, 96); font-size: 1.3em;"><span style="font-size: inherit; line-height: inherit; margin: 0px; display: inline-block; font-weight: normal; background: rgb(239, 112, 96); color: rgb(255, 255, 255); padding: 3px 10px 1px; border-top-right-radius: 3px; border-top-left-radius: 3px; margin-right: 3px;">2.JQuery</span><span style="display: inline-block; vertical-align: bottom; border-bottom: 36px solid rgb(239, 235, 233); border-right: 20px solid transparent;"> </span></h3> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">JQuery 是一個 JavaScript 庫。功能包括 HTML 元素選取和操做、CSS 操做、HTML 事件函數、 JavaScript 特效和動畫、HTML DOM 遍歷和修改、AJAX 和 Utilities。除此以外,JQuery 還提供了大量插件。</p> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">基礎語法: $(selector).action()。</p> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">選擇器:主要分四大選擇器,分別是基本選擇器、層次選擇器、過濾選擇器、屬性過濾選擇器。</p> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">事件:例如 click()、dblclick()、mouseenter()、mouseleave()、mousedown()等。</p> <h3 id="h3cookie" style="color: inherit; line-height: inherit; padding: 0px; margin: 1.6em 0px; font-weight: bold; border-bottom: 2px solid rgb(239, 112, 96); font-size: 1.3em;"><span style="font-size: inherit; line-height: inherit; margin: 0px; display: inline-block; font-weight: normal; background: rgb(239, 112, 96); color: rgb(255, 255, 255); padding: 3px 10px 1px; border-top-right-radius: 3px; border-top-left-radius: 3px; margin-right: 3px;">3.Cookie</span><span style="display: inline-block; vertical-align: bottom; border-bottom: 36px solid rgb(239, 235, 233); border-right: 20px solid transparent;"> </span></h3> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">在 web 程序中是使用 HTTP 協議來傳輸數據的,由於 http 是無狀態協議,一旦數據交換完畢,客戶端和服務器端的鏈接就會關閉,再次交換數據須要創建新的鏈接,因此沒法實現會話跟蹤,cookie 技術則彌補了這一缺陷。</p> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">cookie 實際上一段的文本信息,客戶端請求服務器。若是服務器須要記錄該用戶的狀態,就使用 response 向客戶端瀏覽器頒發一個 cookie。客戶端瀏覽器會把 cookie 保存起來。當瀏覽器再請求該網站時,瀏覽器把請求的網址連同該 cookie 一同提交給服務器。服務器檢查該 cookie,以此來辨認用戶的狀態。服務器還能夠根據須要修改 cookie 的內容。</p> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">cookie 生命週期:</p> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">cookie 的 maxAge 決定 cookie 的生命週期,單位爲秒(second)。cookie 經過 getMaxAge() 方法和 setMaxAge()方法來得到 maxAge 屬性,若是 maxAhe 屬性爲正,則表示 cookie 會在 maxAge 秒以後自動失效。若是 maxAge 屬性爲負,則說明 cookie 僅在本瀏覽器窗口和本窗口打開的子窗口下有效,關閉窗口 cookie 則失效。maxAge 的默認值是-1 當 maxAge 的值爲 0 時,表示刪除 cookie。</p> <h3 id="h4session" style="color: inherit; line-height: inherit; padding: 0px; margin: 1.6em 0px; font-weight: bold; border-bottom: 2px solid rgb(239, 112, 96); font-size: 1.3em;"><span style="font-size: inherit; line-height: inherit; margin: 0px; display: inline-block; font-weight: normal; background: rgb(239, 112, 96); color: rgb(255, 255, 255); padding: 3px 10px 1px; border-top-right-radius: 3px; border-top-left-radius: 3px; margin-right: 3px;">4.Session</span><span style="display: inline-block; vertical-align: bottom; border-bottom: 36px solid rgb(239, 235, 233); border-right: 20px solid transparent;"> </span></h3> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">session 也是一種記錄客戶狀態的機制,不一樣的是 cookie 保存在客戶端瀏覽器中,而 session 保存在服務器上。客戶端瀏覽器訪問服務器是時候把客戶端信息以某種形式記錄在服務器上,這就是 session 中查找該客戶的狀態。</p> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">session 生命週期:</p> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">session 保存在服務器端,爲了得到更高的存取速度,服務器通常把 session 放在內存。每一個用戶都會有一個獨立的 session,若是 session 內容過於複雜,當大量客戶訪問服務器時可能會致使內存溢出。</p> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">session 在用戶第一次訪問服務器的時候自動建立,須要注意只有訪問 JSP,Servlet 等程序時纔會建立 session;只要訪問 HTML、IMAGE 等靜態資源不會建立 session。若是還沒有生成session,可使用 request.getSession(true)強制生成 session。</p> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">在建立了Session的同時,服務器會爲該Session生成惟一的Session id,而這個Session id在隨後的請求中會被用來從新得到已經建立的Session</p> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">session 生成後,只要用戶訪問,服務器就會更新 session 的最後訪問時間,並維護該 session。用戶每訪問服務器一次,不管是否續寫 session 服務器都認爲該用戶的 session 活躍(active)了一次。</p> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">Session 對應的類是 javax.servlet.http.HttpSession,每個訪問者都對應一個 session 對象,並將其狀態信息保存在這個 session 對象中,session 對象的建立是在用戶第一次訪問服務器時產生的。</p> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">可是服務端的session的實現對客戶端的cookie有依賴關係的,上面我講到服務端執行session機制時候會生成session的id值,這個id值會發送給客戶端,客戶端每次請求都會把這個id值放到http請求的頭部發送給服務端,而這個id值在客戶端會保存下來,保存的容器就是cookie,所以當咱們徹底禁掉瀏覽器的cookie的時候,服務端的session也會不能正常使用</p> <h3 id="h5forwardredirect" style="color: inherit; line-height: inherit; padding: 0px; margin: 1.6em 0px; font-weight: bold; border-bottom: 2px solid rgb(239, 112, 96); font-size: 1.3em;"><span style="font-size: inherit; line-height: inherit; margin: 0px; display: inline-block; font-weight: normal; background: rgb(239, 112, 96); color: rgb(255, 255, 255); padding: 3px 10px 1px; border-top-right-radius: 3px; border-top-left-radius: 3px; margin-right: 3px;">5.轉發(forward)和重定向(redirect)的區別?</span><span style="display: inline-block; vertical-align: bottom; border-bottom: 36px solid rgb(239, 235, 233); border-right: 20px solid transparent;"> </span></h3> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">轉發是服務器行爲,重定向是客戶端行爲。</p> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">forward(轉發) 是容器中控制權的轉向,是服務器請求資源,服務器直接訪問目標地址的 URL,把那個 URL 的響應內容讀取過來,而後把這些內容再發給瀏覽器,瀏覽器根本不知道服務器發送的內容是從哪兒來的,因此它的地址欄中仍是原來的地址。</p> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">redirect(重定向) 就是服務器端根據邏輯,發送一個狀態碼,告訴瀏覽器從新去請求那個地址,所以從瀏覽器的地址欄中能夠看到跳轉後的連接地址,很明顯 redirect 沒法訪問到服務器保護起來資源,可是能夠從一個網站 redirect 到其餘網站。</p> <ol style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; padding-left: 32px; list-style-type: decimal;"> <li style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; margin-bottom: 0.5em;"><p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">從地址欄顯示來講: forward是服務器請求資源,服務器直接訪問目標地址的URL,把那個URL的響應內容讀取過來,而後把這些內容再發給瀏覽器.瀏覽器根本不知道服務器發送的內容從哪裏來的,因此它的地址欄仍是原來的地址. redirect是服務端根據邏輯,發送一個狀態碼,告訴瀏覽器從新去請求那個地址.因此地址欄顯示的是新的URL.</p></li> <li style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; margin-bottom: 0.5em;"><p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">從數據共享來講: forward:轉發頁面和轉發到的頁面能夠共享request裏面的數據. redirect:不能共享數據.</p></li> <li style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; margin-bottom: 0.5em;"><p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">從運用地方來講: forward:通常用於用戶登錄的時候,根據角色轉發到相應的模塊. redirect:通常用於用戶註銷登錄時返回主頁面和跳轉到其它的網站等</p></li> <li style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; margin-bottom: 0.5em;"><p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">從效率來講: forward:高. redirect:低.</p></li> </ol> <h3 id="h6" style="color: inherit; line-height: inherit; padding: 0px; margin: 1.6em 0px; font-weight: bold; border-bottom: 2px solid rgb(239, 112, 96); font-size: 1.3em;"><span style="font-size: inherit; line-height: inherit; margin: 0px; display: inline-block; font-weight: normal; background: rgb(239, 112, 96); color: rgb(255, 255, 255); padding: 3px 10px 1px; border-top-right-radius: 3px; border-top-left-radius: 3px; margin-right: 3px;">6.怎麼防止表單重複提交?</span><span style="display: inline-block; vertical-align: bottom; border-bottom: 36px solid rgb(239, 235, 233); border-right: 20px solid transparent;"> </span></h3> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">i.禁掉提交按鈕。表單提交後使用 Javascript 使提交按鈕 disable。</p> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">ii.Post/Redirect/Get 模式。在提交後執行頁面重定向,這就是所謂的 Post-Redirect-Get (PRG) 模式。簡言之,當用戶提交了表單後,你去執行一個客戶端的重定向,轉到提交成功信息頁面。</p> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">iii.在 session 中存放一個特殊標誌。當表單頁面被請求時,生成一個特殊的字符標誌串,存在 session 中,同時放在表單的隱藏域裏。接受處理表單數據時,檢查標識字串是否存在,並當即從 session 中刪除它,而後正常處理數據。</p> <h3 id="h7webxml" style="color: inherit; line-height: inherit; padding: 0px; margin: 1.6em 0px; font-weight: bold; border-bottom: 2px solid rgb(239, 112, 96); font-size: 1.3em;"><span style="font-size: inherit; line-height: inherit; margin: 0px; display: inline-block; font-weight: normal; background: rgb(239, 112, 96); color: rgb(255, 255, 255); padding: 3px 10px 1px; border-top-right-radius: 3px; border-top-left-radius: 3px; margin-right: 3px;">7.web.xml 文件中能夠配置哪些內容?</span><span style="display: inline-block; vertical-align: bottom; border-bottom: 36px solid rgb(239, 235, 233); border-right: 20px solid transparent;"> </span></h3> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">web.xml 用於配置 Web 應用的相關信息,如:監聽器(listener)、過濾器(filter)、 Servlet、相關參數、會話超時時間、安全驗證方式、錯誤頁面等</p> <h3 id="h8servlet" style="color: inherit; line-height: inherit; padding: 0px; margin: 1.6em 0px; font-weight: bold; border-bottom: 2px solid rgb(239, 112, 96); font-size: 1.3em;"><span style="font-size: inherit; line-height: inherit; margin: 0px; display: inline-block; font-weight: normal; background: rgb(239, 112, 96); color: rgb(255, 255, 255); padding: 3px 10px 1px; border-top-right-radius: 3px; border-top-left-radius: 3px; margin-right: 3px;">8. servlet聲明週期?</span><span style="display: inline-block; vertical-align: bottom; border-bottom: 36px solid rgb(239, 235, 233); border-right: 20px solid transparent;"> </span></h3> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">Initialization 初始化</p> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">Service 服務</p> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">Distory 銷燬</p> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">1.init()。當Servlet第一次被裝載時,Servlet引擎調用這個Servlet的init()方法,只調用一次。若是某個Sevlet須要特殊的初始化須要。那麼Servlet編寫人員能夠重寫該方法來執行初始化任務。若是某個Servlet不須要初始化,那麼默認狀況下將調用它父類的init方法。系統保證,在init方法成功完成之前,是不會調用Servlet去處理任何請求的。</p> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">2.service()。這是Servlet最重要的方法,是真正處理請求的地方。對於每一個請求,Servlet引擎將調用Servlet的service方法,並把Servlet請求對象和Servlet響應對象最爲參數傳遞給它。</p> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">3.destroy()。這是相對於init的可選方法,當Servlet即將被卸載時由Servlet引擎來調用,這個方法用來清除並釋放在init方法中所分配的資源</p> <h3 id="h9jspweb" style="color: inherit; line-height: inherit; padding: 0px; margin: 1.6em 0px; font-weight: bold; border-bottom: 2px solid rgb(239, 112, 96); font-size: 1.3em;"><span style="font-size: inherit; line-height: inherit; margin: 0px; display: inline-block; font-weight: normal; background: rgb(239, 112, 96); color: rgb(255, 255, 255); padding: 3px 10px 1px; border-top-right-radius: 3px; border-top-left-radius: 3px; margin-right: 3px;">9.Jsp類置對象(Web開發中的四個域對象)</span><span style="display: inline-block; vertical-align: bottom; border-bottom: 36px solid rgb(239, 235, 233); border-right: 20px solid transparent;"> </span></h3> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">範圍小到大:<br> page(jsp有效) page域指的是pageContext.<br> request(一次請求) request域指的是request HttpServletRequest<br> session(一次會話) session 域指的是 session HTTPSession<br> application(當前web應用) application 域指的是 application ServletContext</p> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">4個對象的生命週期(生命週期就是值對象的建立到銷燬的期間):<br> page:jsp頁面被執行,生命週期開始,jsp頁面執行完畢,聲明週期結束。<br> request:用戶發送一個請求,開始,服務器返回響應,請求結束,生命週期結束。<br> session:用戶打開瀏覽器訪問,建立session(開始),session超時或被聲明失效,該對象生命週期結束。<br> application:web應用加載的時候建立。Web應用被移除或服務器關閉,對象銷燬。【結束】<br>appliction: ServletContext<br>session: HttpSession<br>request: HttpServletRequest<br>response:HttpServletResponse<br>pageContext: PageContext<br>out: JspWriter<br>config: ServletConfig<br>page: this</p> <h3 id="h10dogetdopost" style="color: inherit; line-height: inherit; padding: 0px; margin: 1.6em 0px; font-weight: bold; border-bottom: 2px solid rgb(239, 112, 96); font-size: 1.3em;"><span style="font-size: inherit; line-height: inherit; margin: 0px; display: inline-block; font-weight: normal; background: rgb(239, 112, 96); color: rgb(255, 255, 255); padding: 3px 10px 1px; border-top-right-radius: 3px; border-top-left-radius: 3px; margin-right: 3px;">10.doGet 和doPost區別</span><span style="display: inline-block; vertical-align: bottom; border-bottom: 36px solid rgb(239, 235, 233); border-right: 20px solid transparent;"> </span></h3> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">get方式將參數放在url後面,在請求行, post方式將參數放在請求的正文部分。<br>get方式參數顯示在地址欄,不安全, post參數地址欄不可見,相對安全。<br>地址欄的參數長度有限制,post無限制<br>若是未重寫service()方法,則執行父類的service()方法,起調度做用,若是是get請求就調動doGet()若是是post請求就調用doPost()<br>若是重寫了service()方法,即便重寫了doGet()或doPost()也只會調用service()方法</p> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">3.提交數據的安全<br>POST比GET方式的安全性要高<br>經過GET提交數據,用戶名和密碼將明文出如今URL上,由於一下幾個緣由get方式安全性會比post弱:<br>(1)登陸頁面有可能被瀏覽器緩存<br>(2)其餘人查看瀏覽器的歷史紀錄,那麼別人就可 以拿到你的帳號和密碼了<br>(3)當趕上跨站的攻擊時,安全性的表現更差了</p> <h3 id="h11http" style="color: inherit; line-height: inherit; padding: 0px; margin: 1.6em 0px; font-weight: bold; border-bottom: 2px solid rgb(239, 112, 96); font-size: 1.3em;"><span style="font-size: inherit; line-height: inherit; margin: 0px; display: inline-block; font-weight: normal; background: rgb(239, 112, 96); color: rgb(255, 255, 255); padding: 3px 10px 1px; border-top-right-radius: 3px; border-top-left-radius: 3px; margin-right: 3px;">11.HTTP協議下請求和響應的格式</span><span style="display: inline-block; vertical-align: bottom; border-bottom: 36px solid rgb(239, 235, 233); border-right: 20px solid transparent;"> </span></h3> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">請求格式:請求行 請求頭 請求正文部分<br>響應格式:響應狀態行 響應頭 響應內容</p> <h3 id="h12requestgetattributerequestgetparameter" style="color: inherit; line-height: inherit; padding: 0px; margin: 1.6em 0px; font-weight: bold; border-bottom: 2px solid rgb(239, 112, 96); font-size: 1.3em;"><span style="font-size: inherit; line-height: inherit; margin: 0px; display: inline-block; font-weight: normal; background: rgb(239, 112, 96); color: rgb(255, 255, 255); padding: 3px 10px 1px; border-top-right-radius: 3px; border-top-left-radius: 3px; margin-right: 3px;">12. request.getAttribute() 和 request.getParameter() 有何區別?</span><span style="display: inline-block; vertical-align: bottom; border-bottom: 36px solid rgb(239, 235, 233); border-right: 20px solid transparent;"> </span></h3> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">request.getAttribute()是獲取屬性值<br>request.getParameter()是得到請求中值</p> <h3 id="h13servletfilter" style="color: inherit; line-height: inherit; padding: 0px; margin: 1.6em 0px; font-weight: bold; border-bottom: 2px solid rgb(239, 112, 96); font-size: 1.3em;"><span style="font-size: inherit; line-height: inherit; margin: 0px; display: inline-block; font-weight: normal; background: rgb(239, 112, 96); color: rgb(255, 255, 255); padding: 3px 10px 1px; border-top-right-radius: 3px; border-top-left-radius: 3px; margin-right: 3px;">13.Servlet和Filter的區別:</span><span style="display: inline-block; vertical-align: bottom; border-bottom: 36px solid rgb(239, 235, 233); border-right: 20px solid transparent;"> </span></h3> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">整的流程是:Filter對用戶請求進行預處理,接着將請求交給Servlet進行處理並生成響應,最後Filter再對服務器響應進行後處理。</p> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">Filter有以下幾個用處:<br>Filter能夠進行對特定的url請求和相應作預處理和後處理。<br>在HttpServletRequest到達Servlet以前,攔截客戶的HttpServletRequest。<br>根據須要檢查HttpServletRequest,也能夠修改HttpServletRequest頭和數據。<br>在HttpServletResponse到達客戶端以前,攔截HttpServletResponse。<br>根據須要檢查HttpServletResponse,也能夠修改HttpServletResponse頭和數據。<br>實際上Filter和Servlet極其類似,區別只是Filter不能直接對用戶生成響應。實際上Filter裏doFilter()方法裏的代碼就是從多個Servlet的service()方法裏抽取的通用代碼,經過使用Filter能夠實現更好的複用。</p> <h3 id="h14filterservlet" style="color: inherit; line-height: inherit; padding: 0px; margin: 1.6em 0px; font-weight: bold; border-bottom: 2px solid rgb(239, 112, 96); font-size: 1.3em;"><span style="font-size: inherit; line-height: inherit; margin: 0px; display: inline-block; font-weight: normal; background: rgb(239, 112, 96); color: rgb(255, 255, 255); padding: 3px 10px 1px; border-top-right-radius: 3px; border-top-left-radius: 3px; margin-right: 3px;">14. Filter和Servlet的生命週期</span><span style="display: inline-block; vertical-align: bottom; border-bottom: 36px solid rgb(239, 235, 233); border-right: 20px solid transparent;"> </span></h3> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">1.Filter在web服務器啓動時初始化<br>2.若是某個Servlet配置了 1 ,該Servlet也是在Tomcat(Servlet容器)啓動時初始化。<br>3.若是Servlet沒有配置1 ,該Servlet不會在Tomcat啓動時初始化,而是在請求到來時初始化。<br>4.每次請求, Request都會被初始化,響應請求後,請求被銷燬。<br>5.Servlet初始化後,將不會隨着請求的結束而註銷。<br>6.關閉Tomcat時,Servlet、Filter依次被註銷。</p> <h3 id="h15jspservlet" style="color: inherit; line-height: inherit; padding: 0px; margin: 1.6em 0px; font-weight: bold; border-bottom: 2px solid rgb(239, 112, 96); font-size: 1.3em;"><span style="font-size: inherit; line-height: inherit; margin: 0px; display: inline-block; font-weight: normal; background: rgb(239, 112, 96); color: rgb(255, 255, 255); padding: 3px 10px 1px; border-top-right-radius: 3px; border-top-left-radius: 3px; margin-right: 3px;">15. Jsp與Servlet區別</span><span style="display: inline-block; vertical-align: bottom; border-bottom: 36px solid rgb(239, 235, 233); border-right: 20px solid transparent;"> </span></h3> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">1.JSP的本質就是Servlet,JSP頁面在執行的時候都會被服務器端的JSP引擎轉換爲Servelet(.java),而後又由JSP引擎調用Java編譯器,將Servelet(.java)編譯爲Class文件(.class),並由Java虛擬機(JVM)解釋執行。<br>2.Servlet中沒有內置對象,Jsp中的內置對象都是必須經過HttpServletRequest對象,HttpServletResponse對象以及HttpServlet對象獲得。<br>3.Servlet在Java代碼中經過HttpServletResponse對象動態輸出HTML內容,JSP在靜態HTML內容中嵌入Java代碼,Java代碼被動態執行後生成HTML內容。<br>4.JSP側重於界面表現,Servlet主要用於控制邏輯</p> <h3 id="h16servlet" style="color: inherit; line-height: inherit; padding: 0px; margin: 1.6em 0px; font-weight: bold; border-bottom: 2px solid rgb(239, 112, 96); font-size: 1.3em;"><span style="font-size: inherit; line-height: inherit; margin: 0px; display: inline-block; font-weight: normal; background: rgb(239, 112, 96); color: rgb(255, 255, 255); padding: 3px 10px 1px; border-top-right-radius: 3px; border-top-left-radius: 3px; margin-right: 3px;">16.Servlet的調用過程</span><span style="display: inline-block; vertical-align: bottom; border-bottom: 36px solid rgb(239, 235, 233); border-right: 20px solid transparent;"> </span></h3> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">1.瀏覽器輸入訪問路徑後,攜帶了請求行,頭,體<br>2.根據訪問路徑找到已註冊的servlet名稱<br>3.根據映射找到對應的servlet名<br>4.根據根據servlet名找到咱們全限定類名,既咱們本身寫的類<br>5.服務器找到全限定類名後,經過反射建立對象,同時也建立了servletConfig,裏面存放了一些初始化信息(注意服務器只會建立一次servlet對象,因此servletConfig也只有一個)</p> <h3 id="h18httphttps" style="color: inherit; line-height: inherit; padding: 0px; margin: 1.6em 0px; font-weight: bold; border-bottom: 2px solid rgb(239, 112, 96); font-size: 1.3em;"><span style="font-size: inherit; line-height: inherit; margin: 0px; display: inline-block; font-weight: normal; background: rgb(239, 112, 96); color: rgb(255, 255, 255); padding: 3px 10px 1px; border-top-right-radius: 3px; border-top-left-radius: 3px; margin-right: 3px;">18. HTTP與HTTPS有什麼區別?</span><span style="display: inline-block; vertical-align: bottom; border-bottom: 36px solid rgb(239, 235, 233); border-right: 20px solid transparent;"> </span></h3> <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;"> HTTP協議傳輸的數據都是未加密的,也就是明文的,所以使用HTTP協議傳輸隱私信息很是不安全,爲了保證這些隱私數據能加密傳輸,因而網景公司設計了SSL(Secure Sockets Layer)協議用於對HTTP協議傳輸的數據進行加密,從而就誕生了HTTPS。簡單來講,HTTPS協議是由SSL+HTTP協議構建的可進行加密傳輸、身份認證的網絡協議,要比http協議安全。</p></div>java