JSP - SPLessons

Chapter 41



JSP HTTP Codes – The HTTP stands for “hyper text transfer protocol” used to provide the communication between the server and the browser. While requesting the server through the browser, data will be sent through the HTTP by URL link. Sometimes errors may be occurring due to server problem or browser problems, these errors will be indicated by codes will be in number formats, by using those codes client can easily understand the problem.
JSP HTTP Codes – The GET method is the default method to pass data from client to web server and it delivers a long string that shows up in the browser’s Location. Never utilize the GET method in the event that you have secret key or other touchy data to go to the server. The GET method has size constraint: just 1024 characters can be in a solicitation string.
The solid method for passing data to a backend code is the POST method. This method bundles the data in the very same route as GET strategies, yet as opposed to sending it as a content string after a ? in the URL it sends it as a different message. This message goes to the back end program as the standard information which one can parse and use for preparing.Following are the some important status codes.

Status codes

Following are the different status codes.

Code Message Description
101 Continue Only a part of the solicitation has been gotten by the server, however the length of it has not been rejected, the customer should continue with the solicitation.
200 Ok Request is ok
202 Granted The request granted but not completed.
204 No Content Server got the request but data is not there to send.
302 Found Asked page has moved to new URL briefly.
400 Not Found Server can’t discover the solicitation page.
401 Unauthorized This page needs user name and password.
404 Bad Request Server is unable to get the request.
408 Request Time out The server was waiting to give reply.
500 Internal Server Error Problem was caused by server.
503 Service Unavailable Server down
505 HTTP Version not supported Server is not supporting to HTTP version.

Methods Description
public void sendRedirect(String url) Gives 302 response and gives URL of new record.
public void setStatus ( int statusCode ) It takes int as an argument, setStatus before really giving back any of the substance with the PrintWriter.
public void sendError(int code, String message) It sends the  error  with shot message to the client.


	  <title>Setting HTTP Status Code</title>
response.sendError(407, "Need authentication!!!" );// Set error code and reason.

Output will be as follows, where in code given code is 407 means that page needs a authentication.


  • JSP HTTP Codes – In HTTP Get() is used to retrieve the data from the resource.
  • JSP HTTP Codes – In POST() is used to accept the data and stores the data.