Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Jsp Retrieve HTTP Request Headers using JSP

Related Tutorials


 
 

Share on Google+Share on Google+

Retrieve HTTP Request Headers using JSP

Advertisement
When a HTTP client sends a request, it is required to supply GET or POST. It can send a number of headers.

Retrieve HTTP Request Headers using JSP

     

This section illustrates you how to retrieve the request headers.

When a HTTP client sends a request, it is required to supply GET or POST. It can send a number of headers. Here are some headers:

 

 

 

 

 

Accept - MIME type, the browser prefers.
Accept-Charset - The Character set the browser expects.
Accept-Language - The language which the browser is accepting.
Connection - If a servlet gets a keep-Alive value or gets a 
request line indicating HTTP 1.1, it may be able to take advantage of connection.
Host (host and port as defined in url).
Content-Length (for POST messages).
User-Agent (type of browser, if servlet is returning browser-specific content).

We are providing you an example which explains you clearly.

Here is the code of headers.jsp

<%@ page import="java.util.*" %>
<html>
<head>
<title>Http Request Headers Example</title>
</head>
<body>
<h2>HTTP Request Headers Received</h2>
<table>
<%
Enumeration enumeration = request.getHeaderNames();
while (enumeration.hasMoreElements()) {
String name = (String) enumeration.nextElement();
String value = request.getHeader(name);
%>
<tr><td><%= name %></td><td><%= value %></td></tr>
<%
}
%>
</table>
</body>
</html>

In the above example, we have created an object of class Enumeration by calling the method getHeaderNames() of the request object. This method provides the different header names and their information.

Output will be displayed as

Download Source Code

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: August 5, 2008

Related Tutorials

Discuss: Retrieve HTTP Request Headers using JSP   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0
DMCA.com