

{"id":81351,"date":"2020-08-31T09:00:50","date_gmt":"2020-08-31T03:30:50","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=81351"},"modified":"2021-08-25T13:47:31","modified_gmt":"2021-08-25T08:17:31","slug":"jsp-client-request-server-response","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/jsp-client-request-server-response\/","title":{"rendered":"JSP Client Request and Server Response"},"content":{"rendered":"<p>Welcome to DataFlair JSP Client Request and Server Response Tutorial. This article is the detailed study of Client Request and Server Response in JSP along with their headers. It also discusses the methods available to use these headers to retrieve the required information. So without wasting time, let&#8217;s proceed.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/JSP-Client-Request-Server-Response-1.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-81411\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/JSP-Client-Request-Server-Response-1.jpg\" alt=\"JSP Client Request and se\" width=\"1200\" height=\"628\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/JSP-Client-Request-Server-Response-1.jpg 1200w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/JSP-Client-Request-Server-Response-1-300x157.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/JSP-Client-Request-Server-Response-1-1024x536.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/JSP-Client-Request-Server-Response-1-150x79.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/JSP-Client-Request-Server-Response-1-768x402.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/JSP-Client-Request-Server-Response-1-520x272.jpg 520w\" sizes=\"auto, (max-width: 1200px) 100vw, 1200px\" \/><\/a><\/p>\n<h2>JSP Client Request and Server Response<\/h2>\n<p>When a browser requests for a web page, it sends a lot of information to the webserver. This information sent by the browser gets stored in the header of this HTTP request. This information can be used using HttpServletRequest implementation. We can use different headers that store the information in the request object. Various methods can retrieve information about these Http Headers.<\/p>\n<p><strong>Different headers are:<\/strong><\/p>\n<table>\n<tbody>\n<tr>\n<td><b>S.No<\/b><span style=\"font-weight: 400\">.<\/span><\/td>\n<td><b>Header<\/b><\/td>\n<td><b>Information<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">1.<\/span><\/td>\n<td><b>Accept<\/b><\/td>\n<td><span style=\"font-weight: 400\">This header gives the information about MIME types a browser can handle. The most common example can be Image\/png or Image\/jpeg, depending on what the browser supports.\u00a0<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">2.<\/span><\/td>\n<td><b>Accept-charset<\/b><\/td>\n<td><span style=\"font-weight: 400\">This header gives the information regarding the character sets the browser can use while displaying the information. For example, the browser can use ISO-8599-1 and give this information as a header.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">3.<\/span><\/td>\n<td><b>Accept-Encoding<\/b><\/td>\n<td><span style=\"font-weight: 400\">This header will give the information about the encoding used by the browser. For example, the header can show gzip or compress as the encoding that the browser uses.\u00a0<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">4.<\/span><\/td>\n<td><b>Accept-language<\/b><\/td>\n<td><span style=\"font-weight: 400\">If the servlet is capable of producing output in more than one language, then this header will show the language used. For example, en, ru, en_us.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">5.<\/span><\/td>\n<td><b>Authorization<\/b><\/td>\n<td><span style=\"font-weight: 400\">When the web pages are password protected, the clients can use this header to authorize and identify themselves.\u00a0<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">6.<\/span><\/td>\n<td><b>Connection<\/b><\/td>\n<td><span style=\"font-weight: 400\">This header will give the information about the connection a client can handle. A client can support either persistent or non-persistent connections. Persistent connection supports multiple files in one request, whereas non-persistent connection will require setting up again and again.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">7.<\/span><\/td>\n<td><b>Content-length<\/b><\/td>\n<td><span style=\"font-weight: 400\">This header tells about the content length for POST methods. This header returns the length of the post method in bytes.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">8.<\/span><\/td>\n<td><b>Cookie<\/b><\/td>\n<td><span style=\"font-weight: 400\">This header will return cookies to the server that they sent to the browser previously.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">9.<\/span><\/td>\n<td><b>Host<\/b><\/td>\n<td><span style=\"font-weight: 400\">This header will give the knowledge of hosts and ports of the original URL of the page.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">10.<\/span><\/td>\n<td><b>If-Modified since<\/b><\/td>\n<td><span style=\"font-weight: 400\">This header shows that if the page has been modified since the specified date, then only the client wants that page.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">11.<\/span><\/td>\n<td><b>If-Unmodified since<\/b><\/td>\n<td><span style=\"font-weight: 400\">This header, unlike the above header, will show the page to the client if the page hasn\u2019t been modified i.e., the page is older than the specified date.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">12.<\/span><\/td>\n<td><b>Referrer<\/b><\/td>\n<td><span style=\"font-weight: 400\">This header will contain the information of the page that referred to another page i.e., if webpage 1 referred to webpage 2 then the referrer of the header will contain the information of web page 1.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">13.<\/span><\/td>\n<td><b>User-Agent<\/b><\/td>\n<td><span style=\"font-weight: 400\">This header will give the information of the client or browser that has made the particular request.<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>Request \u2013 Object of HttpServletRequest Implementation<\/h3>\n<p>This is an in-built implicit object of javax.servlet.http.HttpServletRequest. It is passed as a parameter to jspService method. This instance is created each time a request is generated. Using this object we can request a parameter session, cookies, header information, server name, server port, contentType, character encoding, etc. The syntax to use request is:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">request.methodname(\u201cvalue\u201d);\r\n<\/pre>\n<p><strong>Methods used to retrieve information of HTTP headers :<\/strong><\/p>\n<table>\n<tbody>\n<tr>\n<td><b>S.No.<\/b><\/td>\n<td><b>Method<\/b><\/td>\n<td><b>Description<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">1.<\/span><\/td>\n<td><b>Cookie getCookies()<\/b><\/td>\n<td><span style=\"font-weight: 400\">This method will return the array that has all cookie objects that the client sent along with this request.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">2.<\/span><\/td>\n<td><b>Enumeration getAttributeNames()<\/b><\/td>\n<td><span style=\"font-weight: 400\">This method will return the name of all the attributes in an enumeration related to this request.\u00a0<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">3.<\/span><\/td>\n<td><b>Enumeration getHeaderNames()<\/b><\/td>\n<td><span style=\"font-weight: 400\">This method will return an enumeration of names of all the headers concerned.\u00a0<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">4.<\/span><\/td>\n<td><b>Enumeration getParameterNames()<\/b><\/td>\n<td><span style=\"font-weight: 400\">This method will return an enumeration of parameter names related to the request.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">5.<\/span><\/td>\n<td><b>HttpSession getSession()<\/b><\/td>\n<td><span style=\"font-weight: 400\">This method returns the session that\u00a0 relates to the request. If the request doesn\u2019t possess a session, then it will create a session.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">6.<\/span><\/td>\n<td><b>HttpSession getSession( boolean create)<\/b><\/td>\n<td><span style=\"font-weight: 400\">This method will return the HttpSession currently associated with the request. If the request doesn\u2019t have a session and the value of create is true then it will create a new session.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">7.<\/span><\/td>\n<td><b>Locale getLocale()<\/b><\/td>\n<td><span style=\"font-weight: 400\">This method will return the Locale value preferred by the client. It is the content language that the client accepts on the basis of header Accept Language.\u00a0<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">8.<\/span><\/td>\n<td><b>Object getAttribute(String name)<\/b><\/td>\n<td><span style=\"font-weight: 400\">This method will return the value of the attribute mentioned. If it doesn\u2019t find one then it will return null.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">9.<\/span><\/td>\n<td><b>ServletInputStream getInputStream()<\/b><\/td>\n<td><span style=\"font-weight: 400\">This method will return the converted binary data of the body of the request using ServletInputStream.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">10.<\/span><\/td>\n<td><b>String getAuthType()<\/b><\/td>\n<td><span style=\"font-weight: 400\">This method will return the authentication type used to protect the servlet. It can be \u2018SSL\u2019, \u2018BASIC\u2019 or null if the page is not protected.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">11.<\/span><\/td>\n<td><b>String getCharacterEncoding()<\/b><\/td>\n<td><span style=\"font-weight: 400\">This method will return the character encoding that was used in the body of the concerned request.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">12.<\/span><\/td>\n<td><b>String getContentType()<\/b><\/td>\n<td><span style=\"font-weight: 400\">This method will return the content type of the request body. It returns null if the content type is unknown.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">13<\/span><\/td>\n<td><b>String getContextPath()<\/b><\/td>\n<td><span style=\"font-weight: 400\">This method returns the part of the URI that represents the context of the page.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">14.<\/span><\/td>\n<td><b>String getHeader(String name)<\/b><\/td>\n<td><span style=\"font-weight: 400\">This method will return the string type of value of the requested header.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">15.<\/span><\/td>\n<td><b>String getMethod()<\/b><\/td>\n<td><span style=\"font-weight: 400\">This method will return the HTTP method that the request used. It can be GET, POST, etc.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">16.<\/span><\/td>\n<td><b>String getParameter(String name)<\/b><\/td>\n<td><span style=\"font-weight: 400\">The method will return the value of the parameter requested. It returns null if it doesn\u2019t find one.\u00a0<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">17.<\/span><\/td>\n<td><b>String getPathInfo()<\/b><\/td>\n<td><span style=\"font-weight: 400\">It returns any extra information related to the path that the client might have sent along with the request.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">18.<\/span><\/td>\n<td><b>String getProtocol()<\/b><\/td>\n<td><span style=\"font-weight: 400\">This method will return the version and name of the protocol used by the request.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">19.<\/span><\/td>\n<td><b>String getQueryString()<\/b><\/td>\n<td><span style=\"font-weight: 400\">This method returns the part of the URL of the request after the question mark (?) sign called as query string.\u00a0<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">20.<\/span><\/td>\n<td><b>String getRemoteAddr()<\/b><\/td>\n<td><span style=\"font-weight: 400\">This method gets or says returns the IP (Internet Protocol) of the client that made the request.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">21.<\/span><\/td>\n<td><b>String getRemoteHost()<\/b><\/td>\n<td><span style=\"font-weight: 400\">This method will return the name of the client that made the request.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">22.<\/span><\/td>\n<td><b>String getRemoteUser()<\/b><\/td>\n<td><span style=\"font-weight: 400\">This method will return the login information of the user that made the request only if the user is authentic. It returns null otherwise.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">23.<\/span><\/td>\n<td><b>String getRequestURI()<\/b><\/td>\n<td><span style=\"font-weight: 400\">This method will return the portion of URL starting from protocol to Query present in the HTTP request.\u00a0<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">24.<\/span><\/td>\n<td><b>String getRequestedSessionId()<\/b><\/td>\n<td><span style=\"font-weight: 400\">This method will return the session ID given by the client.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">25.<\/span><\/td>\n<td><b>String getServletPath()<\/b><\/td>\n<td><span style=\"font-weight: 400\">This method will return the portion of the request URL that is called the JSP page.\u00a0<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">26.<\/span><\/td>\n<td><b>String getParameterValues(String name)<\/b><\/td>\n<td><span style=\"font-weight: 400\">This method will return an array of all the values that the specified or requested parameter has. This method returns null if the parameter doesn\u2019t exist.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">27.<\/span><\/td>\n<td><b>boolean isSecure()<\/b><\/td>\n<td><span style=\"font-weight: 400\">This method will return a Boolean that indicates if the request was or wasn\u2019t made over a channel that was secure. For example, https.\u00a0<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">28.<\/span><\/td>\n<td><b>int getContentLength()<\/b><\/td>\n<td><span style=\"font-weight: 400\">This method will return the length of content i.e., the body of the request made available by an input stream. This length is in bytes if known, or it returns -1 if the length of the content is unknown.\u00a0<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">29.<\/span><\/td>\n<td><b>int getIntHeader(String name)<\/b><\/td>\n<td><span style=\"font-weight: 400\">This method returns an int value of the header requested.\u00a0<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">30.<\/span><\/td>\n<td><b>int getServerPort()<\/b><\/td>\n<td><span style=\"font-weight: 400\">This method will return the port to which request was made. It returns a port number.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">31.<\/span><\/td>\n<td><b>String getServerName()<\/b><\/td>\n<td><span style=\"font-weight: 400\">This method gives the name of the server to which request was made.<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>This method gives the name of the server to which request was made.<\/p>\n<p><strong>For Example:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&lt;%@ page language=\"java\" contentType=\"text\/html; charset=ISO-8859-1\" pageEncoding=\"ISO-8859-1\" %&gt;\r\n&lt;%@ page import=\"java.io.*,java.util.*\" %&gt;\r\n&lt;html&gt;\r\n&lt;head&gt;\r\n&lt;title&gt;Client Request&lt;\/title&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n&lt;h3&gt;--DataFlair--&lt;\/h3&gt;\r\n&lt;h2&gt;Header Information&lt;\/h2&gt;\r\n &lt;table border=\"1\"&gt;\r\n&lt;tr&gt;\r\n&lt;th&gt;Header&lt;\/th&gt;&lt;th&gt;Header Values&lt;\/th&gt;\r\n&lt;\/tr&gt;\r\n&lt;%\r\n  HttpSession mysession = request.getSession(); \r\n  out.print(\"&lt;tr&gt;&lt;td&gt;Session Name is &lt;\/td&gt;&lt;td&gt;\" +mysession+ \"&lt;\/td.&gt;&lt;\/tr&gt;\");\r\n  Locale mylocale = request.getLocale ();\r\n  out.print(\"&lt;tr&gt;&lt;td&gt;Locale Name is&lt;\/td&gt;&lt;td&gt;\" +mylocale + \"&lt;\/td&gt;&lt;\/tr&gt;\");\r\n  String path = request.getPathInfo(); \r\n  out.print(\"&lt;tr&gt;&lt;td&gt;Path Name &lt;\/td&gt;&lt;td&gt;\" +path+ \"&lt;\/td&gt;&lt;\/tr&gt;\"); \r\n  String method = request.getMethod();\r\n  out.print(\"&lt;tr&gt;&lt;td&gt;Method &lt;\/td&gt;&lt;td&gt;\" +method + \"&lt;\/td&gt;&lt;\/tr&gt;\"); \r\n  String charEncoding = request.getCharacterEncoding();\r\n  out.print(\"&lt;tr&gt;&lt;td&gt;Character Encoding &lt;\/td&gt;&lt;td&gt;\" +charEncoding + \"&lt;\/td&gt;&lt;\/tr&gt;\"); \r\n  String serverName = request.getServerName(); \r\n  out.print(\"&lt;tr&gt;&lt;td&gt;Server Name  &lt;\/td&gt;&lt;td&gt;\" +serverName+ \"&lt;\/td&gt;&lt;\/tr&gt;\");\r\n  int portname = request.getServerPort(); \r\n  out.print(\"&lt;tr&gt;&lt;td&gt;Server Port  &lt;\/td&gt;&lt;td&gt;\" +portname+ \"&lt;\/td&gt;&lt;\/tr&gt;\");\r\n  Enumeration headernames = request.getHeaderNames();\r\n  while(headernames.hasMoreElements()) { \r\n    String parameterName = (String)headernames.nextElement();\r\n    out.print (\"&lt;tr&gt;&lt;td&gt;\" + parameterName + \"&lt;\/td&gt;\" );\r\n    \r\n    String parameterValue = request.getHeader(parameterName);\r\n    out.println(\"&lt;td&gt; \" + parameterValue + \"&lt;\/td&gt;&lt;\/tr&gt;\");\r\n  }\r\n%&gt;\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;\r\n<\/pre>\n<p><strong>Explanation:<\/strong> This example gets the header information using request. We are obtaining information like locale name, path info, server name, port number, enumeration of all the header names using various methods with the request.<\/p>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/image3-3.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-81413\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/image3-3.png\" alt=\"jsp header\" width=\"1366\" height=\"702\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/image3-3.png 1366w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/image3-3-300x154.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/image3-3-1024x526.png 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/image3-3-150x77.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/image3-3-768x395.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/image3-3-520x267.png 520w\" sizes=\"auto, (max-width: 1366px) 100vw, 1366px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<h3>JSP Server Response<\/h3>\n<p>JSP response is created by a server whenever a client makes a request. A typical response may include a status line, response header, blank line, and document.<\/p>\n<p><strong>Response headers are:<\/strong><\/p>\n<table>\n<tbody>\n<tr>\n<td><b>S.No.<\/b><\/td>\n<td><b>Header<\/b><\/td>\n<td><b>Description<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">1.<\/span><\/td>\n<td><b>Allow<\/b><\/td>\n<td><span style=\"font-weight: 400\">This header gives the method of the request that the server can support. It can be GET, PUT, POST.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">2.<\/span><\/td>\n<td><b>Cache-<\/b><\/p>\n<p><b>Control<\/b><\/td>\n<td><span style=\"font-weight: 400\">This header gives the information about the storage of cache data of the response document. It can have the value like private, public, no-cache.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400\">Private cache implies that the document is made for a single user meant to store in non-sharable caches.<\/span><\/p>\n<p><span style=\"font-weight: 400\">Public cache means a document is cacheable.<\/span><\/p>\n<p><span style=\"font-weight: 400\">No-cache means the document is non-cacheable.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">3.<\/span><\/td>\n<td><b>Connection<\/b><\/td>\n<td><span style=\"font-weight: 400\">This header tells the browser to use a persistent(keep alive) connection or a non-persistent (set up required again and again) connection.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">4.<\/span><\/td>\n<td><b>Content-<\/b><\/p>\n<p><b>Disposition<\/b><\/td>\n<td><span style=\"font-weight: 400\">This header lets the browser ask the user regarding saving the response to the file of a given name.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">5.<\/span><\/td>\n<td><b>Content-<\/b><\/p>\n<p><b>Encoding<\/b><\/td>\n<td><span style=\"font-weight: 400\">This header tells the page Encoding that was used at the time of transmission.\u00a0<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">6.<\/span><\/td>\n<td><b>Content-<\/b><\/p>\n<p><b>Language<\/b><\/td>\n<td><span style=\"font-weight: 400\">This header tells the language of the document. It can be en_IN, en_US, ru etc..<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">7.<\/span><\/td>\n<td><b>Content-<\/b><\/p>\n<p><b>Length<\/b><\/td>\n<td><span style=\"font-weight: 400\">This information tells about the length of response. Length is in bytes. It is possible only if the browser uses persistent connection.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">8.<\/span><\/td>\n<td><b>Content-Type<\/b><\/td>\n<td><span style=\"font-weight: 400\">This header specifies <\/span><b>Multipurpose Internet Mail Extension <\/b><span style=\"font-weight: 400\">(MIME) type of the document received in response.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">9.<\/span><\/td>\n<td><b>Expires<\/b><\/td>\n<td><span style=\"font-weight: 400\">This header gives the expiry date of information (out of date). This information should not be cached.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">10.<\/span><\/td>\n<td><b>Last-<\/b><\/p>\n<p><b>Modified<\/b><\/td>\n<td><span style=\"font-weight: 400\">This header gives the information about the last modified time. Using it the client can request for the last modified time.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">11.<\/span><\/td>\n<td><b>Location<\/b><\/td>\n<td><span style=\"font-weight: 400\">This header gets the location of the document and notifies the browser. The browser connects to the location given and retrieves the document.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">12.<\/span><\/td>\n<td><b>Refresh<\/b><\/td>\n<td><span style=\"font-weight: 400\">This header implies that after what time the browser should ask for an updated page. This header refreshes and auto-loads the page after the specified time if the user has specified it.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">13.<\/span><\/td>\n<td><b>Retry-After<\/b><\/td>\n<td><span style=\"font-weight: 400\">This response tells the user that service is unavailable and after how much time it can retry its request.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">14.<\/span><\/td>\n<td><b>Set-Cookie<\/b><\/td>\n<td><span style=\"font-weight: 400\">This header tells about the cookie object related to the page.<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>Response-Object of HttpServletResponse Implementation<\/h3>\n<p>This is an object from HttpServletResponse. This object rather gets passed as a parameter to jspService() like request. It is the response given to the user. One can redirect, get header information, add cookies, send error messages using this object. The Syntax for using response object is:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">response.methodName();\r\n<\/pre>\n<p><strong>Methods that use response object are:<\/strong><\/p>\n<table>\n<tbody>\n<tr>\n<td><b>S.No.<\/b><\/td>\n<td><b>Method<\/b><\/td>\n<td><b> Description<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">1.<\/span><\/td>\n<td><b>String encodeRedirectURL(String url)<\/b><\/td>\n<td><span style=\"font-weight: 400\">This method encodes the URL mentioned that will be used for the sendRedirect method. It returns the unchanged URL, only if encoding is not required.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">2.<\/span><\/td>\n<td><b>String encodeURL(String url)<\/b><\/td>\n<td><span style=\"font-weight: 400\">This method has the capability to encode the mentioned URL with the inclusion of the session ID. It will return the URL unchanged only if the encoding is not a requirement.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">3.<\/span><\/td>\n<td><b>boolean containsHeader(String name)<\/b><\/td>\n<td><span style=\"font-weight: 400\">This method will check if the mentioned header is set or not. Its return type is Boolean value.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">4.<\/span><\/td>\n<td><b>boolean isCommitted()<\/b><\/td>\n<td><span style=\"font-weight: 400\">This method checks and returns a bool value implying that response is committed or not.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">5.<\/span><\/td>\n<td><b>void addCookie(Cookie cookie)<\/b><\/td>\n<td><span style=\"font-weight: 400\">This method will add a cookie to the given response.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">6.<\/span><\/td>\n<td><b>void addDateHeader(String name, long date)<\/b><\/td>\n<td><span style=\"font-weight: 400\">This method will add a header (response header) with the specified name and date as value.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">7.<\/span><\/td>\n<td><b>void addHeader(String name, String value)<\/b><\/td>\n<td><span style=\"font-weight: 400\">This method will add a header (response header) with specified string name and value.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">8.<\/span><\/td>\n<td><b>void addIntHeader(String name, int value)<\/b><\/td>\n<td><span style=\"font-weight: 400\">This method adds a header (response header) with the specified name and value(integer).<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">9.<\/span><\/td>\n<td><b>void flushBuffer()<\/b><\/td>\n<td><span style=\"font-weight: 400\">This method flushes the buffer but the content in the buffer is written to the client before flushing.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">10.<\/span><\/td>\n<td><b>void reset()<\/b><\/td>\n<td><span style=\"font-weight: 400\">This method clears the buffer completely along with headers and status codes<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">11.<\/span><\/td>\n<td><b>void resetBuffer()<\/b><\/td>\n<td><span style=\"font-weight: 400\">This method clears and resets the buffer present in the response. It however doesn\u2019t clear status codes and headers.\u00a0<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">12.<\/span><\/td>\n<td><b>void sendError(int sc)<\/b><\/td>\n<td><span style=\"font-weight: 400\">This method sends the error using the error status code and flushing the buffer.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">13.<\/span><\/td>\n<td><b>void sendError(int sc, String msg)<\/b><\/td>\n<td><span style=\"font-weight: 400\">This method sends a response containing error to the client.\u00a0<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">14.<\/span><\/td>\n<td><b>void sendRedirect(String location)<\/b><\/td>\n<td><span style=\"font-weight: 400\">This method sends a temporary redirect to the client. This redirect can be to a redirect URL specified as the parameter.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">15.<\/span><\/td>\n<td><b>void setBufferSize(int size)<\/b><\/td>\n<td><span style=\"font-weight: 400\">This method sets the buffer size as a preferred one for the response\u2019s body.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">16.<\/span><\/td>\n<td><b>void setCharacterEncoding(String charset)<\/b><\/td>\n<td><span style=\"font-weight: 400\">This method can set the response\u2019s character. For example, UTF-8 etc.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">17.<\/span><\/td>\n<td><b>void setContentLength(int len)<\/b><\/td>\n<td><span style=\"font-weight: 400\">This method sets the content length of the body of response.\u00a0<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">18.<\/span><\/td>\n<td><b>void setContentType(String type)<\/b><\/td>\n<td><span style=\"font-weight: 400\">This method has the ability to set the type of content of the response only if it is not committed.\u00a0\u00a0<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">19.<\/span><\/td>\n<td><b>void setDateHeader(String name, long date)<\/b><\/td>\n<td><span style=\"font-weight: 400\">This method sets the name and date of response headers.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">20.<\/span><\/td>\n<td><b>void setHeader(String name, String value)<\/b><\/td>\n<td><span style=\"font-weight: 400\">This method sets the name and value of the response header.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">21.<\/span><\/td>\n<td><b>void setIntHeader(String name, int value)<\/b><\/td>\n<td><span style=\"font-weight: 400\">This method will set the specified name and integer value as the name and value of the response header.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">22.<\/span><\/td>\n<td><b>void setLocale(Locale loc)<\/b><\/td>\n<td><span style=\"font-weight: 400\">If the response is not committed, then this method will set the locale of the response.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">23.<\/span><\/td>\n<td><b>void setStatus(int sc)<\/b><\/td>\n<td><span style=\"font-weight: 400\">This method will set the status code of the response.<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>For Example:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&lt;%@ page language=\"java\" contentType=\"text\/html; charset=ISO-8859-1\" pageEncoding=\"ISO-8859-1\"%&gt;\r\n&lt;%@ page import=\"java.io.*,java.util.*\" %&gt;\r\n&lt;html&gt;\r\n&lt;head&gt;\r\n&lt;title&gt;Server Response&lt;\/title&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n&lt;h3&gt;--DataFlair--&lt;\/h3&gt;\r\n&lt;h2&gt;Response&lt;\/h2&gt;\r\n&lt;%\r\nLocale mylcl = response.getLocale();\r\nout.println(\"Locale: \" + mylcl + \".\\n\");\r\nresponse.flushBuffer();\r\nPrintWriter op = response.getWriter();\r\nop.println(\"From writer object\");\r\nString cotype = response.getContentType();\r\nout.println(\"The content type : \" + cotype + \".\\n\");\r\nout.newLine();\r\n  response.setIntHeader(\"Refresh\", 5);\r\n  Date mydate = new Date();\r\n  out.println(\"Today's date is : \" +mydate.toString() + \".\\n\");\r\n%&gt;\r\n\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;\r\n<\/pre>\n<p><strong>Explanation:<\/strong> This example shows the use of a response object in order to get information like content type, locale value, using flush buffer, writing response directly to output stream, reloading the response and setting a value for the same.<\/p>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/image2-5.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-81414\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/image2-5.png\" alt=\"jsp response server\" width=\"1366\" height=\"264\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/image2-5.png 1366w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/image2-5-300x58.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/image2-5-1024x198.png 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/image2-5-150x29.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/image2-5-768x148.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/image2-5-520x100.png 520w\" sizes=\"auto, (max-width: 1366px) 100vw, 1366px\" \/><\/a><\/p>\n<h3>Introduction &#8211; HTTP Status Codes<\/h3>\n<p>When a request is sent by the client, a response is generated by the server. This response contains a status line that shows HTTP version, status code and a message. This message describes the status code generated by the server.<\/p>\n<p>200 is the default status code that tells that the request is OK. We don\u2019t need to specify this status code.<br \/>\n<strong>Syntax:\u00a0<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">response.sendError(status code, \"error!!!\" )\r\n<\/pre>\n<p><strong>Some status codes are as follows:<\/strong><\/p>\n<table>\n<tbody>\n<tr>\n<td><b>Code<\/b><\/td>\n<td><b>Message<\/b><\/td>\n<td><b>Description<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">100<\/span><\/td>\n<td><b>Continue<\/b><\/td>\n<td><span style=\"font-weight: 400\">Server received only a portion of the request but the client should continue until the server rejects the request.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">101<\/span><\/td>\n<td><b>Switching Protocols<\/b><\/td>\n<td><span style=\"font-weight: 400\">The server may intend to switch protocol.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">200<\/span><\/td>\n<td><b>OK<\/b><\/td>\n<td><span style=\"font-weight: 400\">The request is fine.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">201<\/span><\/td>\n<td><b>Created<\/b><\/td>\n<td><span style=\"font-weight: 400\">A new source has been created as the request was complete.\u00a0<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">202<\/span><\/td>\n<td><b>Accepted<\/b><\/td>\n<td><span style=\"font-weight: 400\">Request is accepted for processing<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">203<\/span><\/td>\n<td><b>Non-authoritative Information<\/b><\/td>\n<td><span style=\"font-weight: 400\">Information in the requested page is non-authoritative<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">204<\/span><\/td>\n<td><b>No Content<\/b><\/td>\n<td><span style=\"font-weight: 400\">No content available.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">205<\/span><\/td>\n<td><b>Reset Content<\/b><\/td>\n<td><span style=\"font-weight: 400\">Content has been reseted<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">206<\/span><\/td>\n<td><b>Partial Content<\/b><\/td>\n<td><span style=\"font-weight: 400\">Content is partial.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">300<\/span><\/td>\n<td><b>Multiple Choices<\/b><\/td>\n<td><span style=\"font-weight: 400\">The user gets a link list of 5 addresses (maximum). A user can have multiple choices for the locations they wish.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">301<\/span><\/td>\n<td><b>Moved Permanently<\/b><\/td>\n<td><span style=\"font-weight: 400\">This code implies that a new location (URL) is present for the requested page. Simply saying that the page has moved permanently.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">302<\/span><\/td>\n<td><b>Found<\/b><\/td>\n<td><span style=\"font-weight: 400\">This works as status code moves temporarily. This implies that the page has been temporarily moved to a new URL.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">303<\/span><\/td>\n<td><b>See Other<\/b><\/td>\n<td><span style=\"font-weight: 400\">See or go to a different URL to find the page for which request was made.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">304<\/span><\/td>\n<td><b>Not Modified<\/b><\/td>\n<td><span style=\"font-weight: 400\">The page has not been modified.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">305<\/span><\/td>\n<td><b>Use Proxy<\/b><\/td>\n<td><span style=\"font-weight: 400\">Use proxy before accessing the requested page.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">306<\/span><\/td>\n<td><b><i>Unused<\/i><\/b><\/td>\n<td><span style=\"font-weight: 400\">no longer used.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">307<\/span><\/td>\n<td><b>Temporary Redirect<\/b><\/td>\n<td><span style=\"font-weight: 400\">The page that has been requested is redirected to a new location temporarily.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">400<\/span><\/td>\n<td><b>Bad Request<\/b><\/td>\n<td><span style=\"font-weight: 400\">Request was not understood by the server.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">401<\/span><\/td>\n<td><b>Unauthorized<\/b><\/td>\n<td><span style=\"font-weight: 400\">The page that has been requested needs authorization using a username and password.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">402<\/span><\/td>\n<td><b>Payment Required<\/b><\/td>\n<td><span style=\"font-weight: 400\">The client should pay to access the requested page.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">403<\/span><\/td>\n<td><b>Forbidden<\/b><\/td>\n<td><span style=\"font-weight: 400\">Forbidden access to the page requested.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">404<\/span><\/td>\n<td><b>Not Found<\/b><\/td>\n<td><span style=\"font-weight: 400\">Requested page could not be found by the server.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">405<\/span><\/td>\n<td><b>Method Not Allowed<\/b><\/td>\n<td><span style=\"font-weight: 400\">Unallowed method specified in the request.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">406<\/span><\/td>\n<td><b>Not Acceptable<\/b><\/td>\n<td><span style=\"font-weight: 400\">Unacceptable response by the client.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">407<\/span><\/td>\n<td><b>Proxy Authentication Required<\/b><\/td>\n<td><span style=\"font-weight: 400\">authentication must be done using a proxy server before serving the request.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">408<\/span><\/td>\n<td><b>Request Timeout<\/b><\/td>\n<td><span style=\"font-weight: 400\">The request took a longer time to process compared to the time the server was prepared for waiting.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">409<\/span><\/td>\n<td><b>Conflict<\/b><\/td>\n<td><span style=\"font-weight: 400\">Due to the conflict, the request was unable to\u00a0 complete.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">410<\/span><\/td>\n<td><b>Gone<\/b><\/td>\n<td><span style=\"font-weight: 400\">Requested page is unavailable now.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">411<\/span><\/td>\n<td><b>Length Required<\/b><\/td>\n<td><span style=\"font-weight: 400\">The undefined content length causes the rejection of the request.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">412<\/span><\/td>\n<td><b>Precondition Failed<\/b><\/td>\n<td><span style=\"font-weight: 400\">The server evaluates the precondition mentioned in the request as false and rejects the request.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">413<\/span><\/td>\n<td><b>Request Entity Too Large<\/b><\/td>\n<td><span style=\"font-weight: 400\">The entity requested is too large and thus the server doesn&#8217;t accept the request.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">414<\/span><\/td>\n<td><b>Request-url Too Long<\/b><\/td>\n<td><span style=\"font-weight: 400\">The requested URL path is too long and thus the server doesn\u2019t accept requests. For example, conversion of a post request to get request.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">415<\/span><\/td>\n<td><b>Unsupported Media Type<\/b><\/td>\n<td><span style=\"font-weight: 400\">The media type is not supported so the request is not accepted by the server.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">417<\/span><\/td>\n<td><b>Expectation Failed<\/b><\/td>\n<td><span style=\"font-weight: 400\">This implies that the server was unable to fulfil the needs of Expect header field.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">500<\/span><\/td>\n<td><b>Internal Server Error<\/b><\/td>\n<td><span style=\"font-weight: 400\">The request was not complete as the server met an unexpected condition.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">501<\/span><\/td>\n<td><b>Not Implemented<\/b><\/td>\n<td><span style=\"font-weight: 400\">The request was not complete as the server did not support the functionality required.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">502<\/span><\/td>\n<td><b>Bad Gateway<\/b><\/td>\n<td><span style=\"font-weight: 400\">Upstream server sent a response that was not valid so this request was unable to complete.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">503<\/span><\/td>\n<td><b>Service Unavailable<\/b><\/td>\n<td><span style=\"font-weight: 400\">The request was not completed. The server is temporarily overloading or down.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">504<\/span><\/td>\n<td><b>Gateway Timeout<\/b><\/td>\n<td><span style=\"font-weight: 400\">The gateway has timed out.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">505<\/span><\/td>\n<td><b>HTTP Version Not Supported<\/b><\/td>\n<td><span style=\"font-weight: 400\">This implies that the server doesn\u2019t support the specified HTTP protocol version.<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4><strong>Some methods used to set the status codes<\/strong><\/h4>\n<p><strong>1. public void setStatus(int statusCode)<\/strong><br \/>\nThis method will set the arbitrary status code for the JSP Page. If we want a status code in our response or a document, then we should use the function and set int status before returning any object.<\/p>\n<p><strong>2. public void sendRedirect(String URL)<\/strong><br \/>\nThis method will generate a status code 302 response with the location header that gives the URL of the new or redirected document.<\/p>\n<p><strong>3. public void sendError(int code, String message)<\/strong><br \/>\nThis method will set the status code as integer and also an associated message as a string. This is specified inside a HTML document.<\/p>\n<p><strong>Example:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&lt;html&gt;\r\n&lt;head&gt;\r\n&lt;title&gt;HTTP Status Code2&lt;\/title&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n&lt;%\r\nresponse.sendError(404, \"Page Not Found!!!\" );\r\n%&gt;\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;\r\n<\/pre>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&lt;html&gt;\r\n&lt;head&gt;\r\n&lt;title&gt;HTTP Status Code1&lt;\/title&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n&lt;%\r\nresponse.sendError(407, \"Need authentication!!!\" );\r\n%&gt;\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;\r\n<\/pre>\n<p><strong>Explanation:<\/strong> This example uses the sendError method to set two different types of errors with a status code and an associated message.<\/p>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/image4-3.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-81415\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/image4-3.png\" alt=\"jsp server response\" width=\"1366\" height=\"294\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/image4-3.png 1366w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/image4-3-300x65.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/image4-3-1024x220.png 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/image4-3-150x32.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/image4-3-768x165.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/image4-3-520x112.png 520w\" sizes=\"auto, (max-width: 1366px) 100vw, 1366px\" \/><\/a><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/image1-4.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-81412\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/image1-4.png\" alt=\"\" width=\"1366\" height=\"297\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/image1-4.png 1366w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/image1-4-300x65.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/image1-4-1024x223.png 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/image1-4-150x33.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/image1-4-768x167.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/image1-4-520x113.png 520w\" sizes=\"auto, (max-width: 1366px) 100vw, 1366px\" \/><\/a><\/p>\n<h2>Conclusion<\/h2>\n<p>In reference to this article, we came to know about different JSP Client Requests as well as Server Response side. We came to know about headers present for request and response. We also learnt about different methods to retrieve the information of these headers. Further, we discussed the HTTP status codes. We learnt about errors and methods related to them.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Welcome to DataFlair JSP Client Request and Server Response Tutorial. This article is the detailed study of Client Request and Server Response in JSP along with their headers. It also discusses the methods available&#46;&#46;&#46;<\/p>\n","protected":false},"author":10,"featured_media":81411,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[22403],"tags":[23091,23090,23092],"class_list":["post-81351","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-jsp","tag-jsp-client-request","tag-jsp-client-request-and-server-response","tag-jsp-server-response"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>JSP Client Request and Server Response - DataFlair<\/title>\n<meta name=\"description\" content=\"Learn JSP Client Requests &amp; Server Response. JSP response is created by server when client makes request. When request is sent by client, response is generated by server.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/jsp-client-request-server-response\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"JSP Client Request and Server Response - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Learn JSP Client Requests &amp; Server Response. JSP response is created by server when client makes request. When request is sent by client, response is generated by server.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/jsp-client-request-server-response\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2020-08-31T03:30:50+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-08-25T08:17:31+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/JSP-Client-Request-Server-Response-1.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"17 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"JSP Client Request and Server Response - DataFlair","description":"Learn JSP Client Requests & Server Response. JSP response is created by server when client makes request. When request is sent by client, response is generated by server.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/data-flair.training\/blogs\/jsp-client-request-server-response\/","og_locale":"en_US","og_type":"article","og_title":"JSP Client Request and Server Response - DataFlair","og_description":"Learn JSP Client Requests & Server Response. JSP response is created by server when client makes request. When request is sent by client, response is generated by server.","og_url":"https:\/\/data-flair.training\/blogs\/jsp-client-request-server-response\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2020-08-31T03:30:50+00:00","article_modified_time":"2021-08-25T08:17:31+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/JSP-Client-Request-Server-Response-1.jpg","type":"image\/jpeg"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"17 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/jsp-client-request-server-response\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/jsp-client-request-server-response\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/a90b082e16aa38d207212d22b0581f33"},"headline":"JSP Client Request and Server Response","datePublished":"2020-08-31T03:30:50+00:00","dateModified":"2021-08-25T08:17:31+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/jsp-client-request-server-response\/"},"wordCount":2979,"commentCount":0,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/jsp-client-request-server-response\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/JSP-Client-Request-Server-Response-1.jpg","keywords":["jsp client request","JSP Client Request and Server Response","jsp server response"],"articleSection":["JSP Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/jsp-client-request-server-response\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/jsp-client-request-server-response\/","url":"https:\/\/data-flair.training\/blogs\/jsp-client-request-server-response\/","name":"JSP Client Request and Server Response - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/jsp-client-request-server-response\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/jsp-client-request-server-response\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/JSP-Client-Request-Server-Response-1.jpg","datePublished":"2020-08-31T03:30:50+00:00","dateModified":"2021-08-25T08:17:31+00:00","description":"Learn JSP Client Requests & Server Response. JSP response is created by server when client makes request. When request is sent by client, response is generated by server.","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/jsp-client-request-server-response\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/jsp-client-request-server-response\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/jsp-client-request-server-response\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/JSP-Client-Request-Server-Response-1.jpg","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/JSP-Client-Request-Server-Response-1.jpg","width":1200,"height":628,"caption":"JSP Client Request and se"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/jsp-client-request-server-response\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"JSP Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/jsp\/"},{"@type":"ListItem","position":3,"name":"JSP Client Request and Server Response"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/a90b082e16aa38d207212d22b0581f33","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/dd6de0d647a0185cd6faf264e4ba860b0d85d08d7070766f9cd41bea5bb0b227?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/dd6de0d647a0185cd6faf264e4ba860b0d85d08d7070766f9cd41bea5bb0b227?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/dd6de0d647a0185cd6faf264e4ba860b0d85d08d7070766f9cd41bea5bb0b227?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"The DataFlair Team is passionate about delivering top-notch tutorials and resources on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. With expertise in the tech industry, we simplify complex topics to help learners excel. Stay updated with our latest insights.","url":"https:\/\/data-flair.training\/blogs\/author\/dfadteam1\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/81351","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/10"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=81351"}],"version-history":[{"count":2,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/81351\/revisions"}],"predecessor-version":[{"id":81416,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/81351\/revisions\/81416"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/81411"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=81351"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=81351"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=81351"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}