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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容