HTTP Status Codes

Hypertext Transfer Protocol (HTTP) is an application-level protocol for common hypermedia information systems. It is a request/response protocol between clients and servers. It is a generic stateless protocol, used to transfer hypertext.

HTTP Status Codes

Status Codes are used by the client application to know the status of a request processing in the server. The status code has 3 digit numbers, where the first digit defines the class of the response.
The Status code are of 5 categories namely:

  • 1XX – Informational
  • 2XX – Success
  • 3XX – Redirection
  • 4XX – Client Error
  • 5XX – Server Error

Informational Codes

CodeMessage
100Continue
101Switching Protocols

Success Codes

CodeMessage
200OK
201Created
202Accepted
203Non-Authoritative Information
204No Content
205Reset Content
206Partial Content

Redirection Codes

CodeMessage
300Multiple Choices
301Moved Permanently
302Found
303See Other
304Not Modified
305Use Proxy
307Temporary Redirect

Client Error Codes

CodeMessage
400Bad Request
401Unauthorized
402Payment Required
403Forbidden
404Not Found
405Methods Not Allowed
406Not Acceptable
407Proxy Authentication Required
408Request Time-Out
409Conflict
410Gone
411Length Required
412Precondition Failed
413Request Entity Too Large
414Request-URI Too Large
415Unsupported Media Type
416Requested range not satisfy able
417Exceptional Failed

Server Error Codes

CodeMessage
500Internal Server Error
501Not Implemented
502Bad Gateway
503Service Unavailable
504Gateway Time-Out
505HTTP Version not supported

Http Status Codes Example

package javabeat.net.servlets;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class ErrorcodeExample extends HttpServlet {
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		response.sendError(411, "Length Required!!!");
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request, response);
	}
}

Execute the above program, an output as below would be seen:

servlet_httpcode_demo

Previous Tutorial : SingleThreadModel in Servlet  || Next Tutorial : Difference Between Forward And sendRedirect

Comments

comments

About Krishna Srinivasan

He is Founder and Chief Editor of JavaBeat. He has more than 8+ years of experience on developing Web applications. He writes about Spring, DOJO, JSF, Hibernate and many other emerging technologies in this blog.

Speak Your Mind

*