Servlet - Client HTTP Request Last Updated : 30 Jan, 2022 Summarize Comments Improve Suggest changes Share Like Article Like Report When the user wants some information, he/she will request the information through the browser. Then the browser will put a request for a web page to the webserver. It sends the request information to the webserver which cannot be read directly because this information will be part of the header of the HTTP request. Header and DescriptionsHeader Name Description AcceptSpecifies the MIME types (also called Internet Media types or Content types which describe the media type of content served by web servers or applications) that the browser or other clients can handle. Accept-CharsetSpecifies the character sets that the browser can use to display the informationAccept-EncodingSpecifies the types of encodings that the browser supports.Accept-LanguageSpecifies the client's preferred languages in case the servlet can produce results in more than one languageAuthorizationThis is used by clients to identify themselves when accessing password-protected web pagesConnectionThis indicates whether the client can handle HTTP connections or not. Content-LengthThis header is applicable only for POST requests and gives the size of the POST dataCookieThis returns cookies to servers that are previously sent to the browserHostThis specifies the host and port which are given in the original URLMethods which are used to read HTTP HeaderCookie[] getCookies(): Returns all the cookie objects that the client has sent with the requestEnumeration getAttributeNames(): Returns an Enumeration containing the names of the attributes available to this request.Enumeration getHeaderNames(): Returns an Enumeration of all the header names this request contains.Enumeration getParameterNames(): Returns an Enumeration of String Objects which contains the names of the parameters of the current request.HTTPSession getSession(): Returns the session which is associated with this request, if the request does not have a session, then it creates a session for that request.Object getAttribute(String name): returns the value of the named attribute as an object, or null if no attribute with the given name exists.String getContentType(): returns the MIME type of the request, or null if the type is not known.String getMethod(): returns the name of the HTTP method with which the request has been made. The HTTP methods that are used are GET, POST. There are several other methods that are used to read the HTTP Header. Example Java package com.headers; import java.io.IOException; import java.io.PrintWriter; import java.util.Enumeration; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletresponse; // servlet implementation; @WebServlet("/Headers") public class Headers extends HttpServlet { private static final long serialVersionUID = 1L; public Headers() { super(); } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); String str = "Display Header Request"; out.println( "<BODY BGCOLOR=\"#FF5732\">\n" + "<H1 ALIGN=CENTER>" + str + "</H1>\n" + "<B><center>Request Method: <center></B>" + request.getMethod() + "<BR>\n" + "<B>Request URI: </B>" + request.getRequestURI() + "<BR>\n" + "<B>Request Protocol: </B>" + request.getProtocol() + "<BR><BR>\n" + "<TABLE BORDER=1 ALIGN=CENTER>\n" + "<TR BGCOLOR=\"#FFAD00\">\n" + "<TH>Header Name<TH>Header Value"); Enumeration headerNames = request.getHeaderNames(); while (headerNames.hasMoreElements()) { Sting headerName = (String)headerNames.nextElement(); out.println("<TR><TD>" + headerName); out.println("<TD>" + request.getHeader(headerName)); } out.println("<TABLE>\n</BODY></HTML>"); } } Comment More infoAdvertise with us Next Article Servlet - Client HTTP Request M mvkrishna9985vmv Follow Improve Article Tags : Java java-servlet Practice Tags : Java Similar Reads JSP - Client Request In web development, a Client Request refers to a connection sent from a client to a server to edit data, and objects, or to perform or receive operations. In the case of JavaServer Pages (JSP), client requests can be processed using JSP files and servlets running on the web server. In this article, 4 min read Handling HTTP GET and POST Requests in Servlets Understanding how to handle HTTP GET and POST requests in Java Servlets is very important for developing robust web applications. In this article, we will explore how to handle HTTP GET and POST requests in servlets, their key differences, and when to use each. We will also optimize redundant servle 5 min read Servlet - Fetching Result Servlet is a simple java program that runs on the server and is capable to handle requests from the client and generate dynamic responses for the client. How to Fetch a Result in Servlet? It is depicted below stepwise as shown below as follows: You can fetch a result of an HTML form inside a Servlet 3 min read Servlet - Auto Page Refresh The public service(HttpServletRequest req, HttpServletResponse res) method in the servlet component should extend HttpServlet (AC). It allows the browser to refresh the web page when a certain amount of time has passed. Auto-refresh can be enabled in two ways: setHeader(ârefreshâ, String â<time-i 2 min read Tornado- HTTP servers and clients Tornado is a Python web framework and a library for async networks. It is meant for non-blocking, highly effective apps. Tornado has become popular because it can handle large numbers of simultaneous connections easily. In this article, we will explain Tornado HTTP servers and clients. What are HTTP 4 min read Like