HTTP The status code consists of three decimal digits , The first decimal number defines the type of status code , The last two numbers have no role in classification .HTTP Status codes are divided into 5 Types ：
|1**||Information , The server receives the request , Requester is required to continue|
|2**||success , Operation received and processed successfully|
|3**||Redirect , Further action is required to complete the request|
|4**||Client error , The request contains a syntax error or could not be completed|
|5**||Server error , The server encountered an error while processing the request|
HTTP Status code list :
|Status code||English name of status code||Chinese description|
|100||Continue||continue . client Should continue its request|
|101||Switching Protocols||Handover protocol . Server switches protocol according to client's request . Can only switch to a more advanced protocol , for example , Switch to HTTP New version agreement for|
|200||OK||The request is successful . Commonly used in GET And POST request|
|201||Created||Created . Successfully requested and created a new resource|
|202||Accepted||Accepted . Request accepted , But not finished|
|203||Non-Authoritative Information||Unauthorized information . The request is successful . But returned meta The information is not on the original server , It's a copy|
|204||No Content||There is no content . Server processed successfully , But no content returned . Without updating the page , Ensures that the browser continues to display the current document|
|205||Reset Content||Reset Content . Server processed successfully , user terminal （ for example ： browser ） Document view should be reset . You can use this return code to clear the form field of the browser|
|206||Partial Content||Part content . Server successfully processed part GET request|
|300||Multiple Choices||Multiple choice . The requested resource can include multiple locations , Accordingly, a list of resource characteristics and addresses can be returned for the user terminal （ for example ： browser ） choice|
|301||Moved Permanently||A permanent move . The requested resource has been permanently moved to the new URI, The return information will include the new URI, Browser will be automatically directed to new URI. Any new request in the future should use the new URI Instead of|
|302||Found||Temporary movement . And 301 similar . But resources are only temporarily moved . The client should continue to use the original URI|
|303||See Other||View other addresses . And 301 similar . Use GET and POST Request to view|
|304||Not Modified||not changed . The requested resource has not been modified , When the server returns this status code , No resources will be returned . Clients usually cache accessed resources , Indicate by providing a header that the client wants to return only resources modified after a specified date|
|305||Use Proxy||Using agents . The requested resource must be accessed through a proxy|
|306||Unused||Abandoned HTTP Status code|
|307||Temporary Redirect||Temporary redirection . And 302 similar . Use GET request redirections|
|400||Bad Request||Syntax error in client request , Server does not understand|
|401||Unauthorized||Request for user authentication|
|402||Payment Required||Retain , Future use|
|403||Forbidden||The server understands the request from the requesting client , But refused to execute the request|
|404||Not Found||The server could not find the resource at the request of the client （ Webpage ）. By this code , Website designer can set " The resource you requested could not be found " Personal page of|
|405||Method Not Allowed||Method in client request is forbidden|
|406||Not Acceptable||The server could not complete the request based on the content characteristics requested by the client|
|407||Proxy Authentication Required||Request for proxy authentication , And 401 similar , But the requester should use a proxy to authorize|
|408||Request Time-out||Server waits too long for client to send request , Overtime|
|409||Conflict||Server completes client's PUT This code may be returned on request , A conflict occurred while the server was processing the request|
|410||Gone||The resource requested by the client no longer exists .410 differ 404, If the resource has been permanently deleted before, it can be used 410 Code , Website designers can use 301 Code specifies the new location of the resource|
|411||Length Required||The server cannot process the client sent without band Content-Length Request information for|
|412||Precondition Failed||Client request information precondition error|
|413||Request Entity Too Large||Because the requested entity is too large , Server cannot process , So reject the request . To prevent continuous requests from clients , The server may close the connection . If it's just the server that can't handle it temporarily , Will contain a Retry-After Response information for|
|414||Request-URI Too Large||Requested URI Too long （URI Usually web address ）, Server cannot process|
|415||Unsupported Media Type||The server cannot process the media format that came with the request|
|416||Requested range not satisfiable||Invalid range requested by client|
|417||Expectation Failed||Server can't satisfy Expect Request header information for|
|500||Internal Server Error||Server internal error , Unable to complete request|
|501||Not Implemented||The server does not support the requested feature , Unable to complete request|
|502||Bad Gateway||When a server working as a gateway or proxy attempts to execute a request , An invalid response was received from the remote server|
|503||Service Unavailable||Due to overload or system maintenance , The server is temporarily unable to process the client's request . The length of the delay can be included in the server's Retry-After In header information|
|504||Gateway Time-out||Server acting as gateway or proxy , Request not obtained from remote server in time|
|505||HTTP Version not supported||The server does not support the requested HTTP Version of protocol , Unable to complete processing|
What request methods does the server support （ Such as GET、POST etc. ）.
Document coding （Encode） Method . It can only be obtained after decoding Content-Type Content type specified by header . utilize gzip Compressing documents can significantly reduce HTML Download time of document .Java Of GZIPOutputStream It can be carried out easily gzip Compress , But only Unix Upper Netscape and Windows Upper IE 4、IE 5 To support it . therefore ,Servlet Should be checked by Accept-Encoding head （ namely request.getHeader("Accept-Encoding")） Check whether the browser supports gzip, For support gzip Browser return via gzip Compression of the HTML page , Return to normal page for other browsers .
Indicates content length . Only if the browser is persistent HTTP This data is only needed when connecting . If you want to take advantage of persistent connections , Output documents can be written to ByteArrayOutputStream, View its size when finished , Then put the value in the Content-Length head , Finally through byteArrayStream.writeTo(response.getOutputStream() send content .
Indicates what subsequent documents belong to MIME type .Servlet The default is text/plain, But you usually need to explicitly specify as text/html. Due to frequent setting Content-Type, therefore HttpServletResponse Provides a dedicated approach setContentType.
Current GMT Time . You can use it. setDateHeader To set this header to avoid the trouble of converting the time format .
When should the document be considered out of date , So you don't cache it anymore ？
Last change time of document . Customers can use If-Modified-Since Request header provides a date , The request will be treated as a condition GET, Only documents with changes later than the specified time will be returned , Otherwise, return one 304（Not Modified） state .Last-Modified Also available setDateHeader Method to set .
Indicates where the customer should go to extract the document .Location Usually not set directly , But through HttpServletResponse Of sendRedirect Method , This method also sets the status code to 302.
Indicates how long the browser should refresh the document , In seconds . In addition to refreshing the current document , You can also pass setHeader("Refresh", "5; URL=http://host/path") Let browser read the specified page .
Server name .Servlet Generally, this value is not set , But by the Web Server settings .
Set the associated Cookie.Servlet Should not be used response.setHeader("Set-Cookie", ...), Instead, use HttpServletResponse Special methods provided addCookie. See below about Cookie Discussion of settings .
The customer should be Authorization What type of authorization information is provided in the header ？ Include in 401（Unauthorized） This header is required in the response of the status line . for example ,response.setHeader("WWW-Authenticate", "BASIC realm=＼"executives＼"").