In-depth analysis of reading Notes Java Web Technology Insider

Source: Internet
Author: User
Tags domain name server

Chapters: 1

b/S
Advantages of B/s:

The client uses a unified browser (Browser), the unity of the browser brings the unity of operation, regardless of what service is used, because the browser is the same, so the operation is similar. Customer use is simple.
Service-side development simplification; With the unified HTTP protocol, it is easy to develop and can directly use the existing HTTP protocol-based containers, focusing only on business logic.
2.

structure of BS

b/S architecture and front end are based on HTTP protocol interaction data.

The HTTP protocol uses a stateless, short-connected data pattern that once requests a single data interaction, and also corresponds to a business logic.

DNS can resolve domain names to IP addresses

Initiating an HTTP connection is creating a socket connection

The browser F12 can look at the request header and the response header of an HTTP request.

DNS Domain name resolution we do not feel, but very important, the world has several root name servers, the consequences of error is very serious.

steps for DNS to resolve domain names

1. Browser check the cache, if there is the end of the parsing process, the cache has a limited size, time, etc.

Time can be set by TTL

2. Operating system cache, C:\Windows\System32\drivers\etc\hosts file can set the IP address of the domain name, the file in Windows7 is read-only.

3. In the network configuration, the DNS server address is used to solve this, such as the previous two can not be resolved, the operating system to the domain name to ldns local domain name server, generally in the city is not far away, with Ipconfig to query, most of the domain name resolution is completed here.

4. Go to rootserver Domain name Resolver parsing

gTLD International Top-level DNS servers worldwide 13 units

5-10: A first-level return to the local domain name server to your local cache.

(Baidu Encyclopedia)//first pick down to stay with the later view

HTTP client programs, such as browsers, must indicate the type of request (usually get or post) when sending a request to the server. If necessary, the client program can also choose to send additional request headers. Most request headers are not required, except for content-length. Content-length must appear for the POST request. Here are some of the most common HTTP request headers Overview (HttpServletRequest)

Accept: The MIME type acceptable to the browser.

Accept-charset: The acceptable character set of the browser.

Accept-encoding: The way the browser can decode data encoding, such as gzip. The servlet can return a GZIP-encoded HTML page to a browser that supports gzip. In many cases this can reduce download time by 5 to 10 times times.

Accept-language: The type of language the browser wishes to use when the server is able to provide more than one language version.

Authorization: Authorization information, which typically occurs in an answer to the Www-authenticate header sent to the server.

Connection: Indicates whether a persistent connection is required. If the servlet sees the value here as "keep-alive", or sees the request using an HTTP 1.1 (HTTP 1.1 is persistent by default), it can take advantage of the persistent connection, when the page contains multiple elements (such as applets, pictures), Significantly reduce the time it takes to download. To do this, the servlet needs to send a content-length header in the answer, and the simplest implementation is to write the content to Bytearrayoutputstream first and then calculate its size before formally writing the content.

Content-length: Represents the length of the request message body.

Cookie: This is one of the most important request header information

From: The email address of the requesting sender, used by some special Web client, is not used by the browser.

Host: The hosts and ports in the initial URL.

If-modified-since: Returns a 304 "not Modified" answer only if the requested content has been modified after the specified date.

Pragma: Specifying a value of "no-cache" means that the server must return a refreshed document, even if it is a proxy server and has a local copy of the page.

Referer: Contains a URL from which the user accesses the currently requested page from the page represented by the URL.

User-agent: Browser type, this value is useful if the content returned by the servlet is related to the browser type.

UA-PIXELS,UA-COLOR,UA-OS,UA-CPU: A nonstandard request header sent by some versions of Internet Explorer to indicate screen size, color depth, operating system, and CPU type.

HTTP Response Header Overview (HttpServletResponse)

The HTTP response of a Web server is generally composed of a status line, one or more answer headers, a blank line, and a content document. Setting the HTTP answer header is often combined with the status code in the Set status line. For example, there are several status codes that indicate that the "document position has changed" is accompanied by a location header, while the 401 (unauthorized) status code must be accompanied by a www-authenticate header.

However, it is useful to specify the answer header even when there is no status code that has special meanings set. The answer header can be used to complete: Set a cookie, specify the date of modification, instruct the browser to refresh the page at a specified interval, declare the length of the document to take advantage of persistent HTTP connections, ... And so many other tasks.

The most common method for setting the answer header is the setheader of the HttpServletResponse, which has two parameters that represent the name and value of the answer header, respectively. Similar to setting the status code, the setup answer header should be done before any document content is sent.

The Setdateheader method and the Setintheadr method are specifically designed to set up an answer header that contains a date and integer value, which avoids the hassle of converting Java time to a GMT time string, which avoids the hassle of converting integers to strings.

HttpServletResponse also offers a number of settings

setContentType: Sets the Content-type header. This method is used by most servlets.

Setcontentlength: Sets the content-length header. This function is useful for browsers that support persistent HTTP connections.

Addcookie: Set a cookie (there is no Setcookie method in the Servlet API, because the answer often contains multiple Set-cookie headers).

Also, as described in the previous section, the Sendredirect method sets the location header when the status Code 302 is set.

HTTP Answer Header Description

Which request methods (such as Get, post, and so on) are supported by the Allow server.

The encoding (Encode) method of the Content-encoding document. The content type specified by the Content-type header can be obtained only after decoding. Using gzip to compress documents can significantly reduce the download time of HTML documents. Java's gzipoutputstream can be easily gzip compressed, but only on Unix Netscape and IE 4, ie 5 on Windows. Therefore, the servlet should check whether the browser supports gzip by looking at the accept-encoding header (that is, Request.getheader ("accept-encoding")). Returns the gzip-compressed HTML page for a browser that supports gzip, returning a normal page for another browser.

Content-length represents the content length. This data is only required if the browser is using a persistent HTTP connection. If you want to take advantage of the persistent connection, you can write the output document to Bytearrayoutputstram, look at its size when done, then put that value into the Content-length header and finally pass the Bytearraystream.writeto ( Response.getoutputstream () Send content.

Content-type indicates what MIME type the subsequent document belongs to. The servlet defaults to Text/plain, but it usually needs to be explicitly specified as text/html. Because Content-type is often set up, HttpServletResponse provides a dedicated method setContentType.

Date the current GMT time. You can use Setdateheader to set this header to avoid the hassle of converting the time format.

When should Expires think that the document has expired so that it does not cache it?

Last-modified The last modification time of the document. The customer can provide a date through the If-modified-since request header, which is treated as a conditional get, and only documents that have been modified later than the specified time are returned, otherwise a 304 (not Modified) state is returned. Last-modified can also be set using the Setdateheader method.

Location indicates where the customer should go to extract the document. Location is usually not set directly, but by HttpServletResponse's Sendredirect method, which sets the status code to 302.

Refresh indicates how much time the browser should refresh the document, in seconds. In addition to refreshing the current document, you can also pass SetHeader ("Refresh", "5; Url=http://host/path ") lets the browser read the specified page. Note This functionality is usually done by setting the HTML page in the head area of the <meta http-equiv= "Refresh" content= "5; Url=http://host/path "> is implemented because automatic refresh or redirection is important for HTML writers who cannot use CGI or servlets. For Servlets, however, it is more convenient to set the refresh header directly. Note that the meaning of refresh is "refresh this page after n seconds or visit the specified page" instead of "refresh this page every n seconds or visit the specified page". Therefore, continuous refresh requires a refresh header to be sent each time, and sending a 204 status code prevents the browser from continuing to refresh, whether it is using the refresh header or the <meta http-equiv= "Refresh" ...>. Note that the refresh header is not part of the HTTP 1.1 formal specification, but rather an extension, but both Netscape and IE support it.

Server name. The servlet generally does not set this value, but is set by the Web server itself.

Set-cookie sets the Cookie associated with the page. The servlet should not use Response.setheader ("Set-cookie", ...), but should use the dedicated method Addcookie provided by HttpServletResponse. See below for a discussion of cookie settings.

Www-authenticate What type of authorization information should customers provide in the authorization header? This header is required in an answer that contains a 401 (unauthorized) status line. For example, Response.setheader ("Www-authenticate", "BASIC realm=\" Executives\ ""). Note that the servlet generally does not handle this, but instead gives the Web server a special mechanism to control access to password-protected pages (for example,. htaccess).

In-depth analysis of reading Notes Java Web Technology Insider

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.