6、Web基礎

Web

靜態web項目

靜態web項目就是一個文件夾。靜態Web項目 就是文件夾中都是靜態資源。

如何將web項目部署到tomcat?

將web項目的文件夾復制到webapps目錄下。比如把test文件夾放進webapps,test文件夾內有一個hello.html。瀏覽器輸入localhost:8080/test/hello.html就能訪問。

動態web項目

動態web項目需要滿足如下目錄結構
項目目錄
|-WEB-INF 文件夾 => 項目配置文件夾,該文件夾下的內容,瀏覽器是訪問不到.
|-classes文件夾 => 放置web項目的字節碼文件.
|-lib文件夾 => 項目中要使用的jar包
|-web.xml文件 => web項目唯一配置文件

Http協議

Http就是一套通訊規范,決定了通訊的格式。

Http請求協議

Get請求

GET / HTTP/1.1     // 請求首行, GET方式

Host: localhost:8080
Connection: keep-alive
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Encoding: gzip, deflate, sdch, br
Accept-Language: zh-CN,zh;q=0.8
Cookie: Idea-433ce01f=0210006b-f85a-4142-9772-8741e9046f6d
// 以上是請求頭,鍵值對的形式

// 請求空行

// 請求正文

Post請求

POST /hello/index.jsp HTTP/1.1    // 請求首行,POST方式

Host: localhost:8080
Connection: keep-alive
Content-Length: 24
Cache-Control: max-age=0
Origin: http://localhost:8080
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36
Content-Type: application/x-www-form-urlencoded
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Referer: http://localhost:8080/hello/
Accept-Encoding: gzip, deflate, br

Cookie: JSESSIONID=E5E2E50D773B6B0F8B0F00F9E88EC100; Idea-433ce01f=0210006b-f85a-4142-9772-8741e9046f6d

響應協議

HTTP/1.1 200    // 響應首行

Content-Type: text/html;charset=ISO-8859-1
Content-Length: 369
Date: Tue, 14 Mar 2017 02:07:26 GMT
// 以上是響應頭

// 這里是響應空行

// 響應正文
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <form action="http://localhost:8080/hello/index.jsp" method="post">
        username: <input type="text" name="name"><br />
        password: <input type="password" name="password"><br />
        <input type="submit">
    </form>
</body>
</html>

狀態碼

  • 200 0K,鏈接成功
  • 404 請求資源未找到
  • 500 服務器內部錯誤
  • 302 重定向,兩次請求。(比如訪問www.360buy.com,會重定向到www.jd.com),實際上經過兩次請求。

by @sunhaiyu

2017.3.15

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容