The HTTP status code of the servlet

Source: Internet
Author: User

The format of the HTTP request and HTTP response message is similar, with the following structure:

Initial status line + carriage return newline character (carriage return + line feed)

0 or more header lines + carriage return line break

A blank line, the carriage return line break

An optional message body, such as file, query data, or query output

For example, the server's response header looks like this:

http/1.1 okcontent-type:text/htmlheader2: ... HeaderN:  ... (Blank line) <!doctype...>

Code message Description

Continue only part of the request has been received by the server, but as long as it is not rejected, the client should continue the request.

101 Switching Protocols Server switch protocol.

The request was successful.

201 Created The request is complete, and a new resource is created.

202 Accepted The request is accepted for processing, but the processing is incomplete.

203 non-authoritative Information

204 No Content

205 Reset Content

206 Partial Content

Multiple Choices link list. The user can select a link to go to that location. Maximum of five addresses.

301 Moved Permanently The requested page has been moved to a new URL.

302 Found The requested page has been temporarily transferred to a new URL.

303 See the page requested by other can be found under a different URL.

304 Not Modified

305 Use Proxy

306 Unused used this code in previous versions. It is no longer used, but the code is still preserved.

307 temporary Redirect The requested page has been temporarily transferred to a new URL.

The requests server does not understand the request.

401 Unauthorized The requested page requires a user name and password.

402 Payment Required You cannot use this code yet.

403 Forbidden prohibits access to the requested page.

404 Not the Found server could not find the requested page.

405 Method Not allowed the methods specified in the request are not allowed.

406 not the acceptable server only generates a response that is not accepted by the client.

407 Proxy authentication Required You must use Proxy server authentication before requesting delivery.

408 Request timeout requests take longer than the server can wait to time out.

409 Conflict Request because the conflict could not be completed.

410 Gone The requested page is no longer available.

411 Length Required "Content-length" is undefined. The server cannot process request information sent by the client without content-length.

The prerequisites given in the 412 precondition Failed request are evaluated by the server as false.

413 Request Entity Too Large The server does not accept the requests because the request entities are too large.

414 Request-url Too A long server does not accept the request because the URL is too long. Occurs when you convert a "post" request to a "get" request with long query information.

The 415 unsupported media type server does not accept the request because the media type is not supported.

417 Expectation Failed

The Internal Server Error has not completed the request. The server encountered an unexpected situation.

501 Not implemented the request was not completed. The server does not support the required functionality.

502 Bad Gateway not completed the request. The server received an invalid response from the upstream server.

503 Service unavailable Incomplete request. The server is temporarily overloaded or crashed.

504 Gateway Timeout.

505 HTTP version not supported server does not support "HTTP protocol" versions.

The following methods can be used to set the HTTP status code in a Servlet program. These methods are available through the HttpServletResponse object.

1 public void setStatus (int statusCode)

This method sets an arbitrary status code. The SetStatus method takes an int (status code) as a parameter. If your response contains a special status code and documentation, make sure to call SetStatus before using PrintWriter to actually return any content.

2 public void sendredirect(String URL)

The method generates a 302 response, along with a location header with a new document URL.

3 public void senderror(int code, String message)

The method sends a status code (typically 404), along with a short message that is automatically formatted and sent to the client inside the HTML document.

The HTTP status code of the servlet

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.