JSP HTTP Status Code

Source: Internet
Author: User

JspHTTP Status Code

HTTP requests are similar in format to HTTP responses, and have the following structure:

    • Start with status line +crlf (carriage return line)
    • 0-line or multi-wardrobe module +crlf
    • A blank line, like CRLF.
    • Optional message body such as file, query data, query output

For example, a server response header looks like this:

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

The status line contains the HTTP version, a status code, and a short message corresponding to the status code.

The following table lists the HTTP status codes and the messages associated with them that may be returned from the server:

Status Code message Description
100 Continue Only part of the request is received by the server, but as long as it is not rejected by the server, the client will continue the request
101 Switching protocols Server Switch Protocol
200 Ok Request is confirmed
201 Created The request is complete and the new resource is created
202 Accepted The request was accepted but not processed
203 Non-authoritative Information
204 No Content
205 Reset Content
206 Partial Content
300 Multiple Choices A hyperlink table that allows the user to select a hyperlink and access, with a maximum of 5 hyperlinks supported
301 Moved Permanently The requested page has been moved to the new URL
60W Found The requested page is temporarily moved to the new URL
303 See other The requested page can be found under a different URL
304 Not Modified
305 Use Proxy
60S Unused This status code is no longer used, but the status code is reserved
307 Temporary Redirect The requested page is temporarily moved to the new URL
400 Bad Request The server does not recognize the request
60s Unauthorized The requested page requires a user name and password
402 Payment Required You cannot use this status code at this time
403 Forbidden Disable access to the requested page
404 Not Found The server could not find the requested page
50T Method not allowed The method specified in the request is not allowed
50W Not acceptable The server can only create a response that the client cannot accept
50V Proxy Authentication Required A proxy server must be authenticated before the request is serviced
408 Request Timeout The request time exceeds the time that the server can wait for the connection to be disconnected
409 Conflict Where the request is contradictory
410 Gone The requested page is no longer available
411 Length Required "Content-length" is not defined and the server refuses to accept the request
412 Precondition Failed The prerequisites for the request are evaluated by the server as False
413 Request Entity Too Large The server refused to accept the request because the requested entity is too large
414 Request-url Too Long The server refused to accept the request because the URL was too long. The large number of query information that comes with the "POST" request being converted to a "GET" request now
415 Unsupported Media Type The server refused to accept the request because the media type is not supported
417 Expectation Failed
500 Internal Server Error The request is incomplete, the server has encountered unexpected situation
501 Not implemented The request is incomplete and the server does not provide the required functionality
40S Bad Gateway The request was incomplete and the server accepted an invalid response from the upstream server
503 Service unavailable The request is incomplete and the server is temporarily restarted or shut down
504 Gateway Timeout Gateway Timeout
505 HTTP Version not supported The server does not support the specified HTTP version
How to set the HTTP status code

The following table lists the methods used to set the status code in the HttpServletResponse class:

S.N. method & Description
1 public void setStatus (int statusCode)

This method can set any status code. If your response contains a special status code and a document, make sure to call the SetStatus method before returning any content with PrintWriter

2 public void Sendredirect (String URL)

This method generates a 302 response while generating a location header to tell the URL of a new document

3 public void Senderror (int code, String message)

This method automatically inserts a status code (typically 404) and a short message into the HTML document and returns it to the client

HTTP Status Code Program example

The next example will send a 407 error code to the browser, and then the browser will tell you "Need authentication!!!".

To access the JSP page above, you will get the following results:

You can also try using other status codes to see if you get any unexpected results.

JSP HTTP Status Code

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.