web-from Java Request object to HTTP protocol

Source: Internet
Author: User
Tags ack diff webp java web

Https://mp.weixin.qq.com/s/PjcA22STEDGwRxVQweObQQ

Where does the request object in the Java Web come from? What is the role of the response object?

Where does the information come from in the session object in the Java Web?

Glossary :

SRC: Source IP, source port, etc.
DST: Destination IP, destination port, etc.
Application Container: Application container, such as Tomcat, Glassfish, parsing and executing Java Servlet, structs and other programs;
Browser: Browser
Client_port: (1024, 65535), not fixed, when the socket is created, the operating system protocol stack autonomous selection;

I. Communication topology diagram

The typical interaction process is as follows:
1. The user clicks the URL or button. Note that this is physically isolated on the client computer, with the server, spanning the mountains and the sea.
2. The browser will URL or button click event, according to the HTTP protocol, encapsulated into HTTP request information, including headers/content;
3. The HTTP protocol sends the request content to the TCP protocol: TCP protocol plus TCP header (including source port and destination port), passed to the IP layer;
4. IP Protocol plus IP header (including source IP address and destination IP address), the TCP message is converted to IP packet, and then to the data link layer;
5. Data Link layer plus MAC head, to the physical layer;
6. Physical Layer Plus physical head, convert the frame into a physical signal sent to the network cable;
7. Intermediate devices (switches, routers, border routers) constantly change the Mac head, the physical head, the IP packet forwarding to the next hop;
8. IP packet across the mountains and the sea, came to the server;
9. The Server de-layer IP header, TCP header, the HTTP request to the HTTP server;
The 10.HTTP server parses the HTTP request header and passes the request information to the application container according to the HTTP protocol;
11. The application container encapsulates the request information into the requests object and creates the response object. Pass the Request/response object to the URL handler (Action);
The 12.URL handler ends after writing the response information to the response object, based on the request information encapsulated by requests;
13. The application container transforms the information contained in the response object into HTTP response information, including the response header and response content, according to the HTTP protocol;
The 14.HTTP server sends the HTTP response information to the browser;
15. Layer Package ...
16. Crossing mountains and seas;
17. The browser receives the HTTP response information and displays the response content;

Two. Final Avatar: HTTP

The browser interacts with the HTTP server through the HTTP protocol, and all communication is done via HTTP.
Include: Information transfer, command request, etc., the command itself is also information.

1. Stone Age
All pages are static HTML pages, and the server returns HTML file contents directly as HTTP, based on the requested URL.
eg.

request:get/news/today.htmlhost:192.168.68.51:8000connection:keep-aliveuser-agent:mozilla/5.0 (Windows NT 6.1) applewebkit/537.36 (khtml, like Gecko) chrome/60.0.3112.113 safari/537.36accept:image/webp,image/apng,image/*,*/*;q =0.8referer:http://192.168.68.51:8000/index.jspaccept-encoding:gzip, Deflateaccept-language:zh-cn,zh;q=0.8,en;q =0.6response:http/1.1 Okserver:apache-coyote/1.1pragma:no-cachecache-control:no-cacheexpires:thu, Jan 1970 00 : 00:02 Gmtcontent-type:image/jpeg;charset=utf-8transfer-encoding:chunkeddate:thu, June 2018 04:57:27 GMT

2. Near-Modern
Select the shtml template file based on the URL of the user request, replace the specific location in the template with dynamic information,
If using the current date, replace the <% date%> in the file;.
Returns the contents of the file after the replacement.

The URL of the user request determines the template file selected.


3. Modern

Division of labor more clear, more detailed.
The HTTP server handles the HTTP protocol, and the application server executes the handler.
Ajax for asynchronous processing.
The URL corresponds to the action class, and the Get/post/update/delete method corresponds to the function to be executed (RESTful);


Three. Life cycle: Request/response & Session & Application

This is for the service side.

The HTTP server and the reference container are usually executed in an application, and when the process starts, application is established and persists during the run of the process.

The session is usually for the user, whether the user is a visitor, or login users, through the browser first access to the server when the session is established,
In subsequent visits, the session continues to exist. Normally, the session will expire automatically. The previous session will also be terminated when the user is logged out.

Each time the browser initiates a URL request, Request/response is created and destroyed.


Four. The role of the application container
Slightly


Ps.

Request the contents of the Mac frame, as shown in the following example:

Packet Info Packet number:315 flags:0x00000000 status:0x00000000 Packet Length:  667 timestamp:13:53:12.025787000 06/21/2018ethernet Type 2 destination:d4:ae:52:c6:74:97  dell:c6:74:97 [0-5] source:34:17:eb:b7:09:4a [6-11] Protocol type:0x0800 IP [12-13]ip Version 4 header-internet Protocol Datagram Version:4 [Mask 0xF0] Header length:5 (bytes) [14 Mask 0x0F] Diff. Services:%00000000 [15] 0000 00.. Default ... XX not-ect total length:649 [16-17] identifier:8245 [18-19] Fragmentation Flags:%010 [Mask 0XE0] 0.. Reserved. 1. Do not Fragment.             0 Last Fragment Fragment offset:0 (0 bytes) [20-21 Mask 0x1fff] Time to live:128 [+] Protocol: 6 Tcp-transmission ControlProtocol [] Header checksum:0x0000 Checksum invalid. Should BE:0XCE3A [24-25] Source IP address:192.168.68.124 [26-29] Dest. IP address:192.168.68.50 [30-33]tcp-transport Control Protocol Source port:53347 [34-35] Destination            port:6080 [36-37] Sequence number:3277077179 [38-41] Ack number:2266623614 [42-45] TCP Offset: 5 (bytes) [0xF0] Reserved:%0000 [mask 0x0F] TCP Flags:%00011000.  . AP ... [47] 0 ... .... (No congestion Window Reduction). 0.. .... (No Ecn-echo). 0 ..... (No Urgent pointer) ... 1 ..... Ack.... 1 ... Push ..... 0.. (No Reset) ... 0. (No SYN) ..... 0 (No FIN) window:64240 [48-49] TCP checksum:0x0c7b Checksum invalid. Should be:0xd73D [50-51] Urgent pointer:0 [52-53] No TCP optionsapplication Layer Data area:get/xxxxxx/xx/x 47 45 54 20 2 F 4E 4E 4E 4E 4E 4E 4E 4E 4E 4E 4E [54-69] xxxx.aspx http/1 6F 31 6E 2E 70-85 []. 1..host:xxxxxx 2E 0D 0A 4 4E 4E 4E 4E 4E 4E 4E 4E 4E 4E 4E [86-101] xxxxxxxxxxx:6080 E 4E 4E 4E 4E 4E 4E [102-117].. Connection:ke 0D 0A 6F 6E 6E 3 A + 6F 6E [118-133] ep-alive. Upgrad 2D 6C, 0D 0A (134-149), E-insecure-reque, 2D, 6E, all in all, 2D 52  [150-165] Sts:1..user-age, 3 a 0D 0A, the 2D of the [166-181] nt:mozilla/5.0 6E 3 a 4D 6F 7A 182-197 6C 6C 31 2F 2E [] (Windows NT 6.1)-6E 6F-2 4E 9 [198-213] applewebkit/537 (6C) 4 B (2F) [214-229]. (khtml, like 2E 33 36 20 4 b 4D 4C 2C 6C 6B [230-245] Gecko) CHROME/6 2 6B 6F 30--------6F 6D  E 2E (2E) [262-277] Ari/537.36..acce (2F), 2E, 0D, 0A, 41 63 63 65  [278-293] Pt:text/html,ap 3 A (2F), 6D 6C 2C [294-309] plication/xhtml+ 6C 69 63 61   6F 6E 2F (310-325) 6D 6C 2B [326-341] xml,application/78 6D 6C 2C----6C xml;q=0.9,image/78 6D 6C 3B 3D 2E 2C 61 6D [342-357] webp,image/apng, All-in-2F 2C 2F 6E (2C) [358-373] */*;q=0.8..accep 2A 2F 2A 3B 3D 2E + 0D 0A [374-389] T-encodi Ng:gzip 2D 6E, 6F, 6E, 3 A, 7A [390-405], deflate. Accep 2C, 6C, 0D, 0A, and 7 [406-421] t-language:zh-c-2D 4C, 6E, 3 a 20 A-2D [422-437] n,zh;q=0.8,en;q= 4E 2C 7A-3B-3D 302E 2C 6E 3B 3D [438-453] 0.6..cookie:ccs 2E 0D 0A 6F 3 a 20 43 43 53 [454-469] =;  Asp.net_sessi 3D 3B, 2E, 4E, 5F, all in. [614-629] onid=14qdlj42ew1 6F 6E (3D)  6A [630-645] 1gzzc2sj5xp2u ...                 (7A 7A), 6A (646-661), 0D 0A 0D. 0A [662]fcs-frame Check Sequence fcs:0xbfdc4562 Calculated

The

responds to Mac frame content, as shown in the following example:

Packet Info Packet number:318 flags:0x00000000 status:0x00000000 Packet Length:  1518 timestamp:13:53:12.062176000 06/21/2018ethernet Type 2 destination:34:17:eb:b7:09:4a [0-5] source:d4:ae:52:c6:74:97 dell:c6:74:97 [6-11] Protocol type:0x0800 IP [12-13]ip versio  N 4 header-internet Protocol Datagram Version:4 [Mask 0xF0] Header length:5 (bytes) [14 Mask 0x0F] Diff. Services:%00000000 [15] 0000 00.. Default ... XX not-ect total length:1500 [16-17] identifier:17809 [18-19] Fragmentation Flags:%010 [Mas K 0xE0] 0.. Reserved. 1. Do not Fragment.             0 Last Fragment Fragment offset:0 (0 bytes) [20-21 Mask 0x1fff] Time to live:128 [+] Protocol: 6 Tcp-transmission ContrOL Protocol [] Header checksum:0xa58b [24-25] Source IP address:192.168.68.50 [26-29] Dest. IP address:192.168.68.124 [30-33]tcp-transport Control Protocol Source port:6080 [34-35] Destination port:53347 [36-37] Sequence number:2266623614 [38-41] Ack number:3277077788 [42-45] TCP Offset : 5 (bytes) [0xF0] Reserved:%0000 [mask 0x0F] TCP Flags:%00010000. ..  A.... [47] 0 ... .... (No congestion Window Reduction). 0.. .... (No Ecn-echo). 0 ..... (No Urgent pointer) ... 1 ..... Ack.... 0 ... (No Push) ..... 0.. (No Reset) ... 0. (No SYN) .....  0 (No FIN) window:64240 [48-49] TCP checksum:0xcd6f [50-51] Urgent pointer:0 [52-53] No TCP Optionsapplication Layer Data area:http/1.1 OK. 2F to 2E, 4F 4 b 0D [54-69]. cache-control:0a, 2D 6F 6E 3, 6F 6C [70-85] No-store. Pragma 6E 6F 2D All-in-a-6F-0D-0A------------6D-----[86-101]: No-cache  Cont 3 A 6E 6F 2D all-in-a-20-0D 0A-6F-6E----[102-117] ent-length:4688 6E 3 2D 4C 6E (34) 36 38 38 [118-133].. content-type:0d 0A 6F 6E, 6E, 2D, 3 A [134-149] text/html; Chars (2F) 6D 6C 3B------[150-165] et=gb2312 Expir 3D (0D 0A) 76 [166-181] es:0..server:m 3 A 53 0D 0A 65 72 65 7-- 2 3 a 4D [182-197] icrosoft-iis/7.5 (6F) 6F 35 (2D), 2F 198-213 X-aspnet-versi 0D 0A, 2D, 3 4E, 2D, and 33, [214-229] ON:4.0.30319..P 6F 6E 3 A, 2E, 2E, and all-in-the-------- 0 0D 0A [230-245] 3p:cp=cao PSA O 3 A, 3D, 4F4F [246-261] UR. P3p:cp=cao 0D 0A 3 A, 3D, 4F [262-277] PSA our.  X-power 4F, 0D 0A, 2D, 6F, and [278-293] ed-by:asp.net.  2D 3 A, 2E 4E, 0D 0A [294-309] Date:thu, Ju 3-A-si-4----2C [310-325] n 2018 05:51:52 6E (3 a) 3 a (+) [326-341] gmt......<! Docty 4D 0D 0A 0D 0A 0D 0A 3C (4F) [342-357] PE HTML PUBLIC "4, 6D, 6C, 4C. 9 [358-373]-//w3c//dtd XHTM 2D 2F 2F All-in-2F 2F------[374-389] L 1.0 Transition 4D   2E (6E) [390-405] al//en "" "/http/+ 6C 2F 2F/4E 3 a 2F 2F (6F) [406-421] Www.w3.org/TR/xh, 2E, 2E 6F, 2F, 31 2F, [422-437] tml1/dtd/xhtml1-74 6D 6C 2 F 2F 6D 6C to 2D [438-453] TRANSITIONAL.DTD 7 6E3 (6F 6E) 6C 2E [454-469] "... 

web-from Java Request object to HTTP protocol

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.