Web
靜態(tài)web項(xiàng)目
靜態(tài)web項(xiàng)目就是一個(gè)文件夾。靜態(tài)Web項(xiàng)目 就是文件夾中都是靜態(tài)資源。
如何將web項(xiàng)目部署到tomcat?
將web項(xiàng)目的文件夾復(fù)制到webapps目錄下。比如把test文件夾放進(jìn)webapps,test文件夾內(nèi)有一個(gè)hello.html。瀏覽器輸入localhost:8080/test/hello.html就能訪問。
動(dòng)態(tài)web項(xiàng)目
動(dòng)態(tài)web項(xiàng)目需要滿足如下目錄結(jié)構(gòu)
項(xiàng)目目錄
|-WEB-INF 文件夾 => 項(xiàng)目配置文件夾,該文件夾下的內(nèi)容,瀏覽器是訪問不到.
|-classes文件夾 => 放置web項(xiàng)目的字節(jié)碼文件.
|-lib文件夾 => 項(xiàng)目中要使用的jar包
|-web.xml文件 => web項(xiàng)目唯一配置文件
Http協(xié)議
Http就是一套通訊規(guī)范,決定了通訊的格式。
Http請(qǐng)求協(xié)議
Get請(qǐng)求
GET / HTTP/1.1 // 請(qǐng)求首行, 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
// 以上是請(qǐng)求頭,鍵值對(duì)的形式
// 請(qǐng)求空行
// 請(qǐng)求正文
Post請(qǐng)求
POST /hello/index.jsp HTTP/1.1 // 請(qǐng)求首行,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
響應(yīng)協(xié)議
HTTP/1.1 200 // 響應(yīng)首行
Content-Type: text/html;charset=ISO-8859-1
Content-Length: 369
Date: Tue, 14 Mar 2017 02:07:26 GMT
// 以上是響應(yīng)頭
// 這里是響應(yīng)空行
// 響應(yīng)正文
<!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>
狀態(tài)碼
- 200 0K,鏈接成功
- 404 請(qǐng)求資源未找到
- 500 服務(wù)器內(nèi)部錯(cuò)誤
- 302 重定向,兩次請(qǐng)求。(比如訪問www.360buy.com,會(huì)重定向到www.jd.com),實(shí)際上經(jīng)過兩次請(qǐng)求。
by @sunhaiyu
2017.3.15