Introduction
Java Server Pages is a scripting-side language that combines several technologies into one powerful, highly scalable technology and helps develop reliable, platform-independent dynamic web applications.
When a browser requests a web page, it sends a lot of information to the webserver. This information can’t be accessed directly as it travels as a part of the header of the HTTP request. . 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 and can be utilized using the HTTPServletRequest.
This article will focus mainly on JSP Server Response and its role in developing a reliable, scalable, and cost-effective web page. Before jumping to the concept of Server Response, you should first know about JSP Client Requests.
JSP Server Response
JSP response is created by the server whenever a client makes a request. When this request is processed, the web server generates a response that typically consists of response headers, a status line (a version of HTML), a blank line, and a document. The web server HTTP response to the web browser can be accessed using JSP.
The JSP Server Response is a response object of HTTPServletResponse class which is an instance of javax.servlet.http.HttpServletResponse object.
Response Headers in JSP
Response Headers in JSP are as follows:
-
Allow: It specifies the request methods that the server supports. It includes methods such as GET, PUT, POST.
-
Cache-Control: It is used to specify the circumstances in which the response document can be cached safely. It can have public, private, or no-cache values.
Public: Document is cacheable.
Private: Document can be used by a single user and can only be stored in private caches.
No-cache: Document should never be cached.
-
Connection: It instructs the web browser to use persistent HTTP connections or not.
Close: It instructs the browser not to use persistent HTTP connections.
Keep-alive: It instructs the browser to use persistent connections.
-
Content-Disposition: It lets the browser ask the user to save the response to the disk in a file of the given name.
-
Content-Encoding: It specifies how the page is encoded during transmission.
-
Content-Language: It signifies the language in which the document is written. E.g., en, ru, en-us, etc.
-
Content-Length: This header tells about the length of the response and also indicates the number of bytes in the response.
-
Content-Type: It gives the Multipurpose Internet Mail Extension (MIME) type in the received response document.
-
Expires: It specifies when the content should be considered out of date. This data should not be cached.
-
Last-Modified: It indicates when the document was last changed.
-
Location: This header gets the document’s location and notifies the web browser. It should be included with all the responses with a status code in the 300s.
-
Refresh: It specifies how soon the browser should ask for an updated page. The page will refresh, and the auto-loads the user has specified a time limit.
-
Retry-After: It tells the client how soon they can repeat their request. It can also be used with a 503 (Service Unavailable) response.
- Set-Cookie: It specifies a cookie associated with the page.