HTTP 1.1 Status Code and Use

xiaoxiao2021-03-06  46

The following sections describe each available status code of the servlet to the HTTP 1.1 client, and standard messages associated with each status code. The understanding of these status codes can significantly increase the ability of servlet, so you should at least take the content of this section and learn about your configuration. When you need some capabilities, you can return to this section to read the specific details. Appendix A (SEVLET and JSP Fast Index) provides summary information of these status codes. Complete HTTP 1.1 specification manual comes from RFC 2616, you can review online at http://www.rfc-editor.org/. The status code of HTTP 1.1 is marked as new features because many browsers only support HTTP 1.0. You should only send the status code to the client that supports HTTP 1.1, and the support protocol version can be checked by calling Request.getRequestProtocol. The remainder of this section describes the status codes in HTTP 1.1 in detail. These status codes are divided into five categories: 100-199 is used to specify certain actions that the client should correspond. 200-299 is used to indicate successful request. 300-399 For files that have been moved and often included in the positioning header information to specify new address information. 400-499 is used to point out the client's error. 500-599 Used to support server errors. The constant in HTTPSERVLETRESPONSE represents the status code that is associated with different standard messages. In the servlet program, you will use the identity of these constants to use the status code. For example: You usually use response.setstatus instead of Response.setStatus (204), because the latter is not easy to understand and easily cause errors. However, you should notice that the server allows a slight change in the message, while the client only pays attention to the digital value of the status code. So the server may only return HTTP / 1.1 200 instead of http / 1.1 200 ok. 100 (Continue / Continue) If the server receives 100-Continue requests in the header information, this means that the client inquiry can send attachments in subsequent requests. In this case, the server uses 100 (SC_CONTINUE) to allow the client to continue or tell the client with 417 (Expection Failed) does not agree to accept attachments. This status code is new in HTTP 1.1. 101 (Switching Protocols / Conversion Protocol) 101 (SC_Switching_Protocols) status code means that the server will change the header information on it into a different protocol. This is newly added in HTTP 1.1. 200 (OK / Normal) 200 (SC_OK) means everything is normal. Generally used for corresponding GET and POST requests. This status code is default for servlet; if you do not call the SetStatus method, you will get 200. 201 (CREATED / Created) 201 (sc_created) indicates a new document in the request's response; its URL should be given in the positioning header information. 202 (Accepted / Accept) 202 (SC_ACCEPTED) Tell the client request is being executed, but it has not been processed. 203 (Non-Authoritative Information / Unofficial Information) Status Code 203 (SC_NON_AUTHORITATIVE_INFORMATION) means that the document is returned normally, but some response header information may be incorrect because the document copy is being used. This is newly added in HTTP 1.1. 204 (no content / no content) does not have a new document, 204 (SC_NO_CONTENT) Make sure the browser continues to display the previous document. This status code is very useful for the user's periodic overloading a page, and you can determine if the previous page has been updated.

For example, a servlet may work as follows: int pageversion = integer.Parseint ("pageversion> = currentversion) {response.SETSTATUS (Response.sc_no_content);} else {// Create REGULAR PAGE} However, this method works on a page that automatically overloads through the refresh response header information or equivalent HTML, because it returns a 204 status code to stop overload. However, the automatic overload based on JavaScript scripts still needs to function in this case. Detailed discussion of this book 7.2 (HTTP 1.1 Response Headers and their Meaning / HTTP 1.1 Response Header and their significance) section can be read. 205 (Reset Content / Reset Content) Reset Content 205 (sc_reset_content) means that although there is no new document, the browser is reset. This status code is used to force the browser to clear the form field. This is newly added in HTTP 1.1. 206 (Partial Content / Part Content) 206 (SC_PARTIAL_CONTENT) is sent when the server completes a partial request containing the RANGE header information. This is newly added in HTTP 1.1. 300 (MULTIPLE Choices / Multiple Selection) 300 (SC_MULTIPLE_CHOICES) indicates that the requested document can be found in multiple places and will be listed in the returned document. If the server has the preferred setting, the preferences will be listed in the positioning header information. 301 (SC_MOVED_PERMANENTLY) status refers to the requested document in other places; the new URL will be given in the positioning header information. The browser will automatically connect to the new URL. 302 (found) and 301 are some, but the URL given in the positioning header information should be understood as a temporary exchange address instead of permanent. Note: In HTTP 1.0, the message is the moved temporrorel rather than being found, so the constant in httpservletresponse is SC_MOVED_TEMPORARILY is not what we think. SC_Found. Note that the constant of the status code 302 is SC_MOVED_TEMPORARILY instead of sc_found. Status code 302 is very useful because the browser is automatically connected to the new URL set in response to the header information. This is very useful, and there is a special method for this purpose - SerndRedirect. Using Response.sendRedirect (URL) than calling response.setstatus (response.sc_moved_temporarily) and response.setheader ("Location", URL). First, the response.sendredirect (URL) method is clearly simple and easy. Second, servlet automatically creates a page to save this connection to provide browsers that cannot be turned automatically. Finally, in the Servlet 2.2 version (version in J2EE), SendRedirect can process relative paths and automatically convert to an absolute path. But you can only use absolute paths in version 2.1. If you turn the user to another page of the site, you have to transfer the URL with the EncodeURL method in HTTPSERVLETRESPONSE. Do you prevent the use of URL-based session tracking. URL rewrite is a method of tracking users who do not use cookies in your website. This is achieved by additional path information at each URL tail, but the Servlet session tracking API will automatically pay attention to these details.

Session Tracking is discussed in Chapter 9, and developing habits using EncodeURL makes it easier to add session tracking in the future. Core Skill If you turn users to other pages of your site, use response.sendredirect (response.encodeurl (URL)) Method to schedule session tracking than just calling response.sendredirect (URL) many. This status can be exchanged with 301. For example, if you have an incorrect access to http: // host / ~ user (path information is incomplete), some servers will reply 301 status code and reply 302. As a result, if the initial request is Get browser just assumed automatic steering. If you want to know more details, please see the discussion of the status code 307. 303 (See Other / See Other Information) This status code is similar to 301, 302, but if the initial request is POST, then the new document (given in the positioning header information) medicinal get. This status code is new to add HTTP 1.1. 304 (Not Modified / To Correction) When the client has a cache document, you can indicate that the client only wants the document when you have changed this document when you have changed this document after the specified date is modified. This approach can be made. 304 (SC_NOT_MODIFIED) means that the buffer version has been updated and the client should refresh the document. In addition, the server will return the requested document and status code 200. Servlet does not set this status code directly. They implements the GetLastModified method and let the default service method processes conditional requests based on the revised date. The routine of this method has been given in 2.8 (An Example Using Servlet Initialization and Page Modification Dates). Examples using servlet initialization and page fixes. 305 (Use Proxy / Using Agent) 305 (SC_USE_PROXY) indicates that the requested document is obtained by the proxy server in the positioning header information. This status code is new to add HTTP 1.1. 307 (Temporary Redirect / Temporary Redirection) Browser Process 307 The rules are the same as 302. The 307 state is added to HTTP 1.1 is due to many browsers, even if the original message is POST, the error is still executed even when the 302 response is received. The browser will be redirected when the browser will be redirected when a 303 response is received. The purpose of adding this new status code is clear: according to the GET and POST request steering when the response is 303; while the 307 response is in response to the GET request steering instead of the POST request. Note: Since some reasons have not had a constant corresponding to this state in httpservletResponse. This status code is new to add HTTP 1.1. Note that there is no SC_TEMPORARY_REDIRECT constant in httpservletResponse, so you can only display the use of 307 status code. 400 (Bad Request / Error Request) 400 (SC_BAD_REQUEST) Indicates the syntax error in the client request. 401 (unauthorized / unauthorized) 401 (sc_unauthorized) indicates that the client is accessible to password-protected pages when there is no valid identity information in the license header information. This response must contain a WWW-Authenticate authorization information header. For example, in the "Restricting Access to Web Pages. /" Restricting Access To Web Pages. / Restriction Access Web page. "403 (Sc_Forbidden) means that the server refuses to provide the requested resource unless you have an authorized otherwise. This state is often caused by damage to the document or directory license on the server.

404 (Not Found / Not found) 404 (SC_NOT_FOUND) Status Each web programmer may have encountered, and he tells the client to find any resource. It is a standard way to indicate "there is no access page". This status code is a common response and has a special method in the HTTPServletResponse class: Senderror ("Message"). The benefit of using Senderror relative to setStatus is: The server automatically generates an error page to display an error message. However, Internet Explorer 5 browser is default ignoring the error pages you play and displays its custom error prompt page, although Microsoft violates HTTP specifications. To close this feature, in the Tools menu, select the Internet option, enter the Advanced Tabs and confirm the "Show Friendly HTTP Error Message" option (in my browser, the 8th options) are not selected. But very few users know this option, so this feature is hidden by IE5 to make users unable to see the information you return to the user. Other mainstream browsers and IE4 are completely displayed by the error prompt page generated by the server. Examples in Figures 6-3 and 6-4 can be referred to. Core Warning By default, IE5 ignores the error prompt page generated by the server. 405 (Method Not ALLOWED / MET) 405 (SC_METHOD_NOT_ALLLOWED) Indicates that the request method (GET, POST, HEAD, PUT, DELETE,, etc.) are not allowed to be used for some specific resources. This status code is new to add HTTP 1.1. 406 (Not Acceptable / Unacceptable) 406 (SC_NOT_ACCEPTABLE) Indicates that the MIME type of the request resource is inconsistent with the type specified in the accept header information in the client. See Table 7.1 (HTTP 1.1 Response Headers and their Meaning / HTTP 1.1 Response Headers and their significance) are introduced to MIME types. 406 is new to add HTTP 1.1. 407 (Proxy Authentication Required / Proxy Requirements) 407 (sc_proxy_authentication_required) is a bit similar to the 401 state, just this state is used for the proxy server. This status indicates that the client must pass the authentication of the proxy server. The proxy server returns a proxy-authenticate response header message to the client, which will cause the client to reconnect using the header information requested by the  蠵 Roxy-Authorization request. This status code is new to add HTTP 1.1. 408 (Request Timeout / Request Timeout) 408 (sc_request_timeout) means that the server is waiting for the client to send a request too long. This status code is new to add HTTP 1.1. 409 (Conflict / Conflict) This state is usually used with the PUT request, and 409 (SC_Conflict) is often used to attempt to disconnect files that are incorrect uploaded. This status code is new to add HTTP 1.1. 410 (GONE / no existence) 410 (sc_gone) tells the client's requesting documentation no longer exist and does not have an updated address. The 410 state is different from 404, 410, is used in the case where the guidance document has been removed, and 404 is used for unwanted reasons. This status code is new to add HTTP 1.1. 411 (Length Required / Require Data Length) 411 (SC_LENGTH_REQUIRED) indicates that the server cannot handle the request (assuming to a POST request with attachment), unless the client sends the Content-Length header information indicates the size of the data sent to the server. This state is new to add HTTP 1.1. 412 (Precondition Failed / Prerequent Condition Error) 412 (SC_PRECondition_failed) Status Indicates that some prerequisites in the request header information are erroneous. This state is new to add HTTP 1.1.

转载请注明原文地址:https://www.9cbs.com/read-56919.html

New Post(0)