Introduction
HTTP stands for HyperText Transfer Protocol. It is an application-level protocol used in distributed, collaborative, hypermedia systems. It is a data communication protocol used to establish communication between client and server.
HTTP is a TCP/IP-based communication protocol used to deliver the data like image files, HTML files, query results, etc., on the web, with the default port being TCP 80. It provides a standardized way for computers to communicate with each other.
This blog will discuss the JSP HTTP status code methods used to set the code, along with some useful examples that will help you understand the concept better.
Source: Link
JSP HTTP Status Code
When a browser requests a web page, a lot of information is sent to the webserver. We cannot access this information directly as it travels as a part of the HTTP request header.
When a web page is requested, it sends information to the server within the HTTP header. This information sent by the browser is stored in the HTTP request header.
When a request is processed, a response is generated. This response status line consists of a status code, HTTP version, and an associated message. This message is directly associated with the status code, and the server determines the HTTP version.
The status code in JSP is already set to 200 by default, so we do not have to change it explicitly.
Format of HTTP Request and Response Message
- A status line + Carriage Return Line Feed(CRLF)
- Zero or more headers + CRLF
- A CRLF
- A message body (optional)
Syntax:
HTTP/1.1 200 OK
Content-Type: text/html
Header2:
(Blank Line)
<!doctype HTML>
<html>
<head>...</head>
<body>
...
</body>
</html>
In the given syntax, HTTP/1.1 represents the HTTP version, 200 represents the status code, and OK represents the short message associated with the code.
HTTP/1.1 200 OK is known as the status line.
However, 200 is the default code representing that the request is OK. It is not necessary to specify it.