HTTP status Code Daquan

Source: Internet
Author: User

The complete HTTP 1.1 specification is from RFC 2616 and can be accessed online at Http://www.talentdigger.cn/home/link.php?url=d3d3LnJmYy1lZGl0b3Iub3JnLw%3D%3D. The status code for HTTP 1.1 is marked as a new feature because many browsers only support HTTP 1.0. You should only send the status code to a 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 main categories:

100-199 is used to specify certain actions that the client should be corresponding.
200-299 is used to indicate a successful request.
300-399 is used for files that have been moved and is often included in the locator header information to specify the new address information.
400-499 is used to indicate client-side errors.
500-599 is used to support server errors.

Constants in HttpServletResponse represent status codes that correlate different standard messages. In a servlet program, you will use the identity of these constants more frequently to work with status codes. For example: You will generally use response.setstatus (response. sc_no_content) instead of Response.setstatus (204), because the latter is not easy to understand and can lead to errors. However, you should note that the server allows slight changes to the message, while the client is only paying attention to the numeric value of the status code. So the server may only return http/1.1 200 instead of http/1.1.

continue/(continued)
If the server receives a request with 100-continue in the header, this means that the client asks if the attachment can be sent in a subsequent request. In this case, the server uses (Sc_continue) to allow the client to continue or use 417 (expectation Failed) to tell the client that it does not agree to accept the attachment. This status code is newly added to HTTP 1.1.

101 (switching protocols/Conversion Protocol)
101 (sc_switching_protocols) status code means that the server will change to a different protocol based on the header information on it. This is the new entry in HTTP 1.1.

(ok/Normal)
(SC_OK) means everything is normal. Typically used for corresponding get and post requests. This status code is default to the servlet, and if you do not call the SetStatus method, you will get 200.

201 (created/created)
201 (sc_created) indicates that the server has created a new document in the requested response, and should give its URL in the anchor header information.

202 (accepted/accepted)
202 (sc_accepted) tells the client that the request is being executed, but has not finished processing it yet.

203 (non-authoritative information/unofficial information)
The Status Code 203 (sc_non_authoritative_information) indicates that the document is returned normally, but some response header information may be incorrect because a copy of the document is being used. This is the new entry in HTTP 1.1.

204 (no content/no content)
In the absence of a new document, 204 (sc_no_content) ensures that the browser continues to display the previous document. These status codes are useful for users to reload a page periodically, and you can determine if the previous page has been updated. For example, a servlet might do the following:
int pageversion =integer.parseint (request.getparameter ("pageversion"));
if (pageversion >;= currentversion) {
Response.setstatus (response. Sc_no_content);
} else {
Create Regular page
}
However, this method works on pages that are automatically overloaded by flushing the response header information or equivalent HTML tags, because it returns an overload after the 204 status code is stopped. However, automatic overloading based on JavaScript scripts still needs to work in this case. You can read the detailed discussion in this book 7.2 (HTTP 1.1 Response Headers and their Meaning/http 1.1 response header information and their meaning) section.

205 (reset content/reset content)
Resetting content 205 (sc_reset_content) means that although there are no new documents, the browser will reset the document display. This status code is used to force the browser to clear form fields. This is the new entry in HTTP 1.1.

206 (partial content/local content)
206 (sc_partial_content) is sent when the server completes a partial request that contains the range header information. This is the new entry in HTTP 1.1.

(multiple choices/multiple options)
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 preferred settings, the preferences will be listed in the location response header information.

301 (Moved permanently)
301 (sc_moved_permanently) state refers to the requested document elsewhere; The new URL of the document is given in the location response header information. The browser will automatically connect to the new URL.

302 (found/found)
Similar to 301, just the URL given in the locator header information should be interpreted as a temporary interchange address instead of permanent. Note: In HTTP 1.0, the message is temporarily moved (Moved temporarily) instead of being found, so the constants in HttpServletResponse are sc_moved_temporarily not what we thought sc_found.

Attention
The constant representing status code 302 is sc_moved_temporarily instead of Sc_found.

Status Code 302 is useful because the browser automatically connects to the new URL that is given in the response header information. This is very useful, and there is a special method for this--sendredirect. Use Response.sendredirect (URL) than call Response.setstatus (response. sc_moved_temporarily) and Response.setheader ("location", url) a few more benefits. First, the Response.sendredirect (URL) method is obviously simple and easy. Second, the servlet automatically creates a page to save the connection for display to browsers that cannot automatically turn. Finally, in the version of Servlet 2.2 (version in Java ee), Sendredirect is able to process relative paths and automatically convert to absolute paths. However, you can only use absolute paths in version 2.1.

If you move the user to another page of the site, you will send the URL using the Encodeurl method in HttpServletResponse. Doing so prevents the continuous use of URL rewrite-based session tracking scenarios. URL rewriting is a way of tracking users who do not use cookies on your website. This is done by appending path information at the end of each URL, but the servlet session trace API automatically takes care of these details. Session tracking is discussed in the Nineth chapter, and the habit of using encodeurl makes it much easier to add session tracking later.

Core Skills
If you turn users to other pages in your site, scheduling session tracking in advance with Response.sendredirect (Response.encodeurl (URL)) is more than just calling Response.sendredirect (URL) is much better.

This status code can sometimes be used in exchange with 301. For example, if you mistakenly access the Http://www.talentdigger.cn/home/link.php?url=aG9zdC9%2BdXNlcg%3D%3D (the path information is incomplete), Some servers will reply to the 301 status code and some reply to 302. Technically, if the initial request is the Get browser is simply assumed to be automatically turned. For more details, see the discussion of status code 307.

303 (see other/for additional information)
This status code is similar to 301 and 302, except that if the initial request is POST, the new document (given in the locator header information) is retrieved as a medicinal get. This status code is newly added to HTTP 1.1.

304 (not modified/for remediation)
When a client has a cached document, it is possible to make a conditional request by providing a If-modified-since header information that indicates that the client only wants the document to be modified after the specified date to be overloaded. 304 (sc_not_modified) means that the buffered version has been updated and the client should refresh the document. Additionally, the server returns the requested document and status Code 200. The servlet generally does not set this status code directly. They implement the Getlastmodified method and let the default service method handle conditional requests based on the remediation date. The routines for this method are given in 2.8 parts (an Example using servlet initialization and page modification dates/A example using servlet initialization and page correction date).

305 (Use proxy/using proxy)
305 (Sc_use_proxy) indicates that the requested document is to be obtained through the proxy server in the location header information. This status code is newly added to HTTP 1.1.

307 (Temporary redirect/temporary redirect)
The browser handles the 307 status with the same rules as 302. The 307 state is added to HTTP 1.1 because many browsers still perform the wrong turn when receiving a 302 response, even if the original message is post. It is only assumed that the browser will redirect at the post request only when the 303 response is received. The purpose of adding this new status code is clear: When the response is 303, the Get and post requests are turned, while in the 307 response the GET request is turned instead of the POST request. Note: For some reason, there are no constants in httpservletresponse that correspond to this state. The status code is newly added to HTTP 1.1.

Attention
There are no Sc_temporary_redirect constants in HttpServletResponse, so you can only display the use of 307 status codes.

(Bad request/error request)
(sc_bad_request) indicates a syntax error in the client request.

401 (unauthorized/not authorized)
401 (sc_unauthorized) indicates that the client accesses a password-protected page when there is no valid identity information in the authorization header information. This response must contain a www-authenticate of the authorization information header. For example, in part 4.5 of this book, the restricting access to Web pages./restricts access to Web pages. ”

403 (forbidden/Forbidden)
403 (Sc_forbidden) means that the server refuses to provide the requested resource unless it has authorization. This state is often caused by a corrupted file or directory license on the server.

404 (not found/found)
404 (Sc_not_found) status each network programmer may have encountered, and he told the client that the address could not find any resources. It is a standard way of saying "no pages visited". This status code is a common response and has a special method in the HttpServletResponse class to implement it: Senderror ("message"). The advantage of using SENDERROR with respect to SetStatus is that the server automatically generates an error page to display the error message. However, the Internet Explorer 5 browser defaults to ignoring the error page you are playing and displays its customized error page, although Microsoft has violated the HTTP specification. To turn off this feature, on the Tools menu, select Internet Options, go to the Advanced tab, and confirm that the "Show friendly HTTP error message" option (in my browser is the bottom 8th option) is not selected. However, few users know this option, so this feature is IE5 hidden and users cannot see the information you return to the user. Other major browsers and IE4 are fully displaying the error page generated by the server. Refer to the examples in figures 6-3 and 6-4.

Core warning
By default, IE5 ignores the error prompt page generated by the server.

405 (Method not allowed/methods not allowed)
405 (sc_method_not_allowed) indicates that the request method (GET, POST, HEAD, PUT, DELETE, and so on) is not allowed for certain specific resources. The status code is newly added to HTTP 1.1.

406 (not acceptable/unreachable)
406 (sc_not_acceptable) indicates that the MIME type of the requested resource is inconsistent with the type specified in the Accept header information in the client. See the description of MIME types in Table 7.1 (HTTP 1.1 Response Headers and their Meaning/http 1.1 response header information and their meaning) in part 7.2 of this book. 406 is newly added in HTTP 1.1.

407 (proxy authentication required/Agent Server authentication requirements)
407 (sc_proxy_authentication_required) is somewhat similar to the 401 state, except that this state is used for proxy servers. This state indicates that the client must be authenticated through a proxy server. The proxy server returns a proxy-authenticate response header information to the client, which causes the client to reconnect using the header information with the proxy-authorization request. The status code is newly added to HTTP 1.1.

408 (Request timeout/requests timeout)
408 (sc_request_timeout) is the length of time that the server waits for a client to send a request. The status code is newly added to HTTP 1.1.

409 (conflict/conflict)
This state is typically used with a put request, and the 409 (sc_conflict) state is often used when attempting to upload an incorrect version of a file. The status code is newly added to HTTP 1.1.

410 (gone/no longer exists)
410 (Sc_gone) tells the client that the requested document is no longer present and does not have an updated address. The 410 status differs from 404,410 in cases where the instruction document has been removed and 404 is used for unknown reasons. The status code is newly added to HTTP 1.1.

411 (length required/requires data lengths)
411 (sc_length_required) indicates that the server cannot process the request (assumed to be a POST request with an attachment) unless the client sends Content-length header information indicating the size of the data sent to the server. The status is newly added to HTTP 1.1.

412 (precondition failed/prerequisite error)
The 412 (sc_precondition_failed) status indicates that some of the prerequisites in the request header information are incorrect. The status is newly added to HTTP 1.1.

413 (Request entity Too large/requested entities too large)
413 (Sc_request_entity_too_large) tells the client that the requested document is now larger than the server wants to handle now. If the server thinks it can be processed over a period of time, it will contain a retry-after response header information. The status is newly added to HTTP 1.1.

414 (Request URI Too long/requested URI too long)
The 414 (Sc_request_uri_too_long) state is used when the URI is too long. The "URI" referred to here refers to the content after the host, domain name, and port number in the URL. For example, in url--http://www.y2k-disaster.com:8080/we/look/silly/now/, the URI refers to/we/look/silly/now/. The status is newly added to HTTP 1.1.

415 (media Format not supported by unsupported media type/)
415 (Sc_unsupported_media_type) means that the format type of the attachment requested by the server does not know how to handle it. The status is newly added to HTTP 1.1.

416 (requested range not satisfiable/request range not satisfied)
416 indicates that the client contains a request that the server cannot satisfy the range header information. The status is newly added to HTTP 1.1. Strangely, there is no corresponding constant in the httpservletresponse of the Servlet 2.1 API to represent that state.

Attention
In the specification of Servlet 2.1, the class HttpServletResponse does not sc_requested_range_not_satisfiable such constants, so you can only use 416 directly. This constant is included after the servlet version 2.2.

417 (expectation failed/expected failure)
If the server gets a expect request header message with a 100-continue value, this means that the client is asking if an attachment can be sent in a later request. In this case, the server will also use that State (417) to tell the browser that the server does not receive the attachment or use the (sc_continue) status to tell the client that the attachment can continue to be sent. The status is newly added to HTTP 1.1.

(Internal server error/internal servers error)
(Sc_internal_server_error) is a common "server error" state. This state is often caused by CGI programs (hopefully not!). is caused by a servlet that is not functioning correctly or that returns a malformed header information.

501 (not implemented/not implemented)
The 501 (sc_not_implemented) state tells the client server that the functionality required in the request is not supported. For example, a client executes a command that is not supported by a server such as put.

502 (Bad gateway/wrong gateway)
502 (Sc_bad_gateway) is used to act as a proxy or gateway server, which indicates that the receiving server received an error response from the remote server.

503 (Service unavailable/services not available)
The Status Code 503 (sc_service_unavailable) indicates that the server is unable to respond because it is maintained or overloaded. For example, if some threads or database connection pools are not already idle, the servlet returns this header information. The server can provide a Retry-after header information to tell the client when it can try again.

504 (Gateway timeout/gateways Timeout)
This state is also used to serve as a proxy or gateway server, which indicates that the receiving server has not received a timely response from the remote server. The status is newly added to HTTP 1.1.

505 (HTTP version not supported/is not supported)
The 505 (sc_http_version_not_supported) status code means that the server does not support the HTTP version indicated in the request. The state is the new HTTP 1.1 added

HTTP status Code Daquan

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.