The following code example demonstrates How to Display HTTP Header Information Using JSP.

Here is an example of a JSP program that displays HTTP header information.

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>HTTP Header Information</title>
</head>
<body>
  <h1>HTTP Header Information</h1>
  <table>
    <tr>
      <th>Header Name</th>
      <th>Header Value</th>
    </tr>
    <%
      Enumeration<String> headerNames = request.getHeaderNames();
      while (headerNames.hasMoreElements()) {
        String headerName = headerNames.nextElement();
        String headerValue = request.getHeader(headerName);
    %>
    <tr>
      <td><%= headerName %></td>
      <td><%= headerValue %></td>
    </tr>
    <%
      }
    %>
  </table>
</body>
</html>

In this example, the JSP page uses a scriptlet to retrieve the HTTP header information from the request object and display it in a table. The getHeaderNames method of the request object returns an enumeration of header names, and the getHeader method is used to retrieve the value of each header. The header names and values are displayed in a table using a loop.


Further Reading

Understanding Enterprise Java Beans

Java Practice Exercise

Princites