Web服务器的工作原理

来源:互联网 发布:哈尔滨工程大学网络 编辑:程序博客网 时间:2024/05/22 09:06

网络服务请求的过程中,有如下实体参与到整个过程当中:

1、HTTP Requests

一个HTTP请求包含以下三个部分:1). Method-URI-Protocol/Version2). Request headers3). Entity body一个HTTP请求的实例如下所示:POST /servlet/default.jsp HTTP/1.1Accept: text/plain; text/html  Accept-Language: en-gb  Connection: Keep-Alive  Host: localhost  Referer: http://localhost/ch8/SendDetails.htm  User-Agent: Mozilla/4.0 (compatible; MSIE 4.01; Windows 98)  Content-Length: 33  Content-Type: application/x-www-form-urlencoded  Accept-Encoding: gzip, deflateLastName=Franks&FirstName=Michael


2、HTTP Responses

一个HTTP回应包含以下三个部分:1). Protocol-Status code-Description2). Response headers3). Entity body一个HTTP回应的实例如下所示:HTTP/1.1 200 OKServer: Microsoft-IIS/4.0Date: Mon, 3 Jan 1998 13:13:33 GMTContent-Type: text/htmlLast-Modified: Mon, 11 Jan 1998 13:23:42 GMTContent-Length: 112<html><head><title>HTTP Response Example</title></head><body>Welcome to Brainy Software</body></html>


3、The Socket Class

在网络上通信,可以采取Socket的形式,也就是说在要通信的两端分别建立一个Socket对象。浏览器端的Socket发送HTTP请求,并接受来自服务器端的HTTP回应。

4、The ServerSocket Class

5、The HttpServer Class

HttpServer代 表web服务器,它通过ServerSocket接收来自浏览器的请求,或者返回被请求的静态资源,或者将请求转交给servlet处理,并将处理结果返 回给浏览器。在HttpServer的入口main()方法中,会调用一个await()方法,等待处理来自浏览器的请求。

6、The Request Class

7、The Response Class

一 个Request对象代表一个HTTP请求,当服务器获取一个HTTP请求时,会根据InputStream创建一个Request对象,然后 Request对象解析出被请求的静态资源或servlet的URI地址,从而将静态资源写入Response对象返回给浏览器,或者是将请求转交给 servlet处理,并将处理结果通过Response对象返回。

原创粉丝点击