A jornada mental de aprender o front-end web------Pontos de conhecimento relacionados a Servlet e protocolo HTTP


insira a descrição da imagem aqui

Servlet outros pontos de conhecimento

  1. Conceito
  2. Etapa
  3. Princípio de execução
  4. Ciclo de vida

  5. Configuração de anotação Servlet3.0

6. Arquitetura de Servlet

Servlet -- 接口
	|
GenericServlet -- 抽象类
	|
HttpServlet  -- 抽象类

* GenericServlet:将Servlet接口中其他的方法做了默认空实现,只将service()方法作为抽象
	* 将来定义Servlet类时,可以继承GenericServlet,实现service()方法即可

* HttpServlet:对http协议的一种封装,简化操作
	1. 定义类继承HttpServlet
	2. 复写doGet/doPost方法

7. Configuração relacionada ao servlet

1. urlpartten:Servlet访问路径
  1. 一个Servlet可以定义多个访问路径 : @WebServlet({"/d4","/dd4","/ddd4"})
  2. 路径定义规则:
	1. /xxx:路径匹配
	2. /xxx/xxx:多层路径,目录结构
	3. *.do:扩展名匹配

HTTP

  Conceito : Hyper Text Transfer Protocol Hyper Text Transfer Protocol
  : define o formato dos dados enviados quando o cliente e o servidor se comunicam

  • Recursos:
  1. Protocolo Avançado Baseado em TCP/IP
  2. Número da porta padrão: 80
  3. Baseado no modelo de solicitação/resposta: uma solicitação corresponde a uma resposta
  4. Stateless: cada solicitação é independente uma da outra e não pode trocar dados
  • Versão histórica:
    1.0: Uma nova conexão é estabelecida para cada solicitação e resposta
    1.1: Conexão multiplexada

Solicitar formato de dados da mensagem

1. 请求行
	请求方式 请求url 请求协议/版本
	GET /login.html	HTTP/1.1

	* 请求方式:
		* HTTP协议有7中请求方式,常用的有2种
			* GET:
				1. 请求参数在请求行中,在url后。
				2. 请求的url长度有限制的
				3. 不太安全
			* POST:
				1. 请求参数在请求体中
				2. 请求的url长度没有限制的
				3. 相对安全
2. 请求头:客户端浏览器告诉服务器一些信息
  请求头名称: 请求头值
    * 常见的请求头:
    	1. User-Agent:浏览器告诉服务器,我访问你使用的浏览器版本信息
		* 可以在服务器端获取该头的信息,解决浏览器的兼容性问题

		2. Referer:http://localhost/login.html
		* 告诉服务器,我(当前请求)从哪里来?
	    	* 作用:
				1. 防盗链:
				2. 统计工作:
3. 请求空行
	空行,就是用于分割POST请求的请求头,和请求体的。
4. 请求体(正文):
	* 封装POST请求消息的请求参数的

Formato de string :

		POST /login.html	HTTP/1.1
		Host: localhost
		User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:60.0) Gecko/20100101 Firefox/60.0
		Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
		Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2
		Accept-Encoding: gzip, deflate
		Referer: http://localhost/login.html
		Connection: keep-alive
		Upgrade-Insecure-Requests: 1
		
		username=zhangsan	

protocolo HTTP

Mensagem de solicitação: dados enviados pelo cliente ao servidor

* 数据格式:
	1. 请求行
	2. 请求头
	3. 请求空行
	4. 请求体

Mensagem de resposta: dados enviados pelo servidor ao cliente

* 数据格式:
  1. 响应行
	1. 组成:协议/版本 响应状态码 状态码描述
	2. 响应状态码:服务器告诉客户端浏览器本次请求和响应的一个状态。
		1. 状态码都是3位数字 
		2. 分类:
	    	1. 1xx:服务器就收客户端消息,但没有接受完成,等待一段时间后,发送1xx多状态码
			2. 2xx:成功。代表:200
			3. 3xx:重定向。代表:302(重定向),304(访问缓存)
			4. 4xx:客户端错误。
			  * 代表:
				* 404(请求路径没有对应的资源) 
				* 405:请求方式没有对应的doXxx方法
			5. 5xx:服务器端错误。代表:500(服务器内部出现异常)
  2. 响应头:
	1. 格式:头名称: 值
	2. 常见的响应头:
		1. Content-Type:服务器告诉客户端本次响应体数据格式以及编码格式
		2. Content-disposition:服务器告诉客户端以什么格式打开响应体数据
			* 值:
				* in-line:默认值,在当前页面内打开
				* attachment;filename=xxx:以附件形式打开响应体。文件下载
  3. 响应空行
  4. 响应体:传输的数据

formato de string de resposta

		HTTP/1.1 200 OK
		Content-Type: text/html;charset=UTF-8
		Content-Length: 101
		Date: Wed, 06 Jun 2018 07:08:42 GMT

		<html>
		  <head>
		    <title>$Title$</title>
		  </head>
		  <body>
		  hello , response
		  </body>
		</html>

insira a descrição da imagem aqui

Acho que você gosta

Origin blog.csdn.net/S_yyuan/article/details/122983603
Recomendado
Clasificación