【正文】
y。 Win 9x 。 URL encoded name/value pairs separated by ampersands. Request Methods As described earlier, GET is the most monly used request method, intended to retrieve a resource without causing anything else to happen on the server. The POST method is almost as mon as GET。s customer number and the list of items to be purchased transferred as parameters. Parameters can be sent in one of two ways: tacked on to the URI in the form of a query string or sent as part of the request message body. This is an example of a URL with a query string: The query string starts with a question mark (?) and consists of name/value pairs separated by ampersands (amp。 all it cares about is getting a response. The response message looks similar to the request message. It consists of three things: a status line, response headers, and an optional response body. Here39。s why the generic term resource is used. In fact, there39。 rv: ) Accept: image/gif, image/jpeg, image/pjpeg, image/png, */* AcceptLanguage : en AcceptCharset : iso88591,*,utf8 The request line specifies the GET method and asks for the resource named / to be returned using the HTTP/ protocol version. The various headers provide additional information. The Host header tells the server the hostname used in the URL. A server may have multiple names, so this information is used to distinguish between multiple virtual web servers sharing the same web server process. The UserAgent header contains information about the type of browser making the request. The server can use this to send different types of responses to different types of browsers. For instance, if the server knows whether Inter Explorer or Netscape Navigator is used, it can send a response that takes advantage of each browser39。s an example of a valid HTTP request message: GET / HTTP/ Host: UserAgent: Mozilla/ (Windows。m trying to use the terms as defined by the HTTP/ specification (RFC2616), which is pretty close to how they are also used in the servlet and JSP specifications. Hence, I use the term URL only when the URI must start with (or , for HTTP over an encrypted connection) followed by a server name and possibly a port number, as in the previous examples. I use URI as a generic term for any string that identifies a resource, where the location can be deduced from the context and isn39。 HTTP39。t allow a web server to differentiate between an explicit request caused by clicking a link or submitting a form and an implicit request caused by resizing the browser window or using the browser39。t easily provide the kind of immediate feedback typically found in standalone GUI applications such as word processors or traditional client/server applications. Every interaction between the client and the server requires a request/response exchange. Performing a request/response exchange when a user selects an item in a list box or fills out a form element is usually too taxing on the bandwidth available to most Inter users. There39。s how it works: a client, typically a web browser, sends a request for a resource to a server, and the server sends back a response corresponding to the resource (or a response with an error message if it can39。 中文 6727 字 翻譯原文 作者: Hans Bergsten HTTP and Servlet Basics Let39。s exactly what the HyperText Transport Protocol (HTTP) is for. The munication model defined by HTTP forms the foundation for all web application design. A basic understanding of HTTP is key to developing applications that fit within the constraints of the protocol, no matter which serverside technology you use. In this chapter, we look at the most important details of HTTP you need to be aware of as a web application developer. One other item: this book is about using JSP as the serverside technology. JSP is based on the Java servlet technology. Both technologies share a lot of terminology and concepts, so knowing a bit about servlets will help you even when you develop pure JSP applications. To really understand and use the full power of JSP, you need to know a fair bit about servlets. Hence, we look at servlet fundamentals in the last section of this chapter. The HTTP Request/Response Model HTTP and all extended protocols based on HTTP are based on a very simple munications model. Here39。t recognize that multiple requests from the same client may be related. Web applications can39。t distinguish between various methods of triggering the request on the client. For example, HTTP doesn39。t detect when the user closes the browser. Over the years, people have developed various tricks to overe the first problem。s address field. To send a request, the browser needs to know which server to talk to and which resource to ask for. This information is specified by an HTTP Uniform Resource Locator (URL): The first part of the URL shown specifies that the request is made using the HTTP protocol. This is followed by the name of the server, in this case . The web server waits for requests to e in on a specific TCP/IP port. Port number 80 is the standard port for HTTP requests. If the web server uses another port, the URL must specify the port number in addition to the server name. For example: This request is sent to a server that uses port 8080 instead of 80. The last part of the URL, /, identifies the resource that the client is requesting. A URL is actually a specialization of a Uniform Resource Identifier (URI, defined in the RFC2396 specification). A URL identifies a resource partly by its location, for instance the server that contains the resource. Another type of URI is a Uniform Resource Name (URN), which is a globally unique identifier that is valid no matter where the resource is located. HTTP deals only with the URL variety. The terms URI and URL are ofte