HTTP status code and Servlet status code of servlet

Source: Internet
Author: User

HTTP status code and Servlet status code of servlet

The format of the HTTP request and the HTTP Response Message is similar. The structure is as follows:

 

Initial status line + carriage return line break (carriage return + line feed)

Zero or multiple heading lines + carriage return line breaks

A blank line, that is, the carriage return line break

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

For example, the response header of the server is as follows:

HTTP/1.1 200 OKContent-Type:text/htmlHeader2: ......HeaderN: ...  (Blank Line)<!doctype...>
 
 

Code Message description

100 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 Switching protocol.

200 OK request 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

300 Multiple Choices link list. You can select a link to enter this location. Up to five addresses are allowed.

301 the page requested by Moved Permanently has been transferred to a new URL.

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

303 the page requested by See Other can be found in another 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 retained.

307 the page requested by Temporary Redirect has been temporarily transferred to a new URL.

400 the Bad Request server does not understand the Request.

401 the user name and password are required for the page requested by Unauthorized.

402 Payment Required you cannot use this code.

403 Forbidden prohibits access to the requested page.

404 Not Found server cannot find the requested page ..

405 Method Not Allowed the Method specified in the request is Not Allowed.

The 406 Not Acceptable server generates only one response Not accepted by the client.

407 Proxy Authentication Required before a request is sent, you must use the Proxy server for Authentication.

408 The Request Timeout takes a longer time than the server can wait and times out.

409 Conflict requests cannot be completed due to conflicts.

410 the page requested by Gone is no longer available.

411 Length Required "Content-Length" is not defined. The server cannot process the request information sent by the client without Content-Length.

412 the prerequisite given in the Precondition Failed request is evaluated by the server as false.

413 the Request Entity Too Large server does not accept this Request because the Request Entity is Too Large.

414 Request-url Too Long server does not accept this Request because the URL is Too Long. It occurs when you convert a "post" request to a "get" request with long query information.

415 the Unsupported Media Type server does not accept this request because the Media Type is not supported.

417 Expectation Failed

500 Internal Server Error incomplete requests. The server encountered an unexpected situation.

501 Not Implemented incomplete requests. The server does not support the required functions.

502 Bad Gateway incomplete requests. The server receives an invalid response from the upstream server.

503 Service Unavailable incomplete requests. The server is temporarily overloaded or crashed.

504 Gateway Timeout Gateway times out.

505 the HTTP Version Not Supported server does Not support the "HTTP protocol" Version.

 

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

 

1 public voidSetStatus(Int statusCode)

This method sets an arbitrary status code. The setStatus method accepts an int (Status Code) as a parameter. If your response contains a special status code and document, make sure to call setStatus before using PrintWriter to actually return anything.

2 public voidSendRedirect(String url)

This method generates a 302 response, along with a Location header with the URL of the new document.

3 public voidSendError(Int code, String message)

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

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.