Getting HTTP Request Headers in a JSP

By: Bruce W. Perry Emailed: 1648 times Printed: 2112 times    

Latest comments
By: rohit kumar - how this program is work
By: Kirti - Hi..thx for the hadoop in
By: Spijker - I have altered the code a
By: ali mohammed - why we use the java in ne
By: ali mohammed - why we use the java in ne
By: mizhelle - when I exported the data
By: raul - no output as well, i'm ge
By: Rajesh - thanx very much...
By: Suindu De - Suppose we are executing

The JSTL v1.0 makes all existing request headers available via the header implicit object. The JSTL automatically makes this variable available to JSPs; the header object evaluates to a java.util.Map type.

In sample program below, the c:forEach tag iterates over this Map and stores each header name and value in the loop variable named by c:forEach's var attribute. The c:forEach var attribute is implemented as a java.util.Map.Entry type, which is a data type that stores keys and their values. The c:out tag displays each header name by using EL format: ${req.key}. Consequently c:out displays the value with ${req.value}.

Viewing the request header names and values in a JSP
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>

<html>
<head><title>Request Headers</title></head>
<body>
<h2>Here are the Request Header names and values</h2>

<c:forEach var="req" items="${header}">

    <strong><c:out value=
        "${req.key}"/></strong>: <c:out value="${req.value}"/><br>

</c:forEach>

</body>
</html>

JSP Home | All JSP Tutorials | Latest JSP Tutorials

Sponsored Links

If this tutorial doesn't answer your question, or you have a specific question, just ask an expert here. Post your question to get a direct answer.



Bookmark and Share

Comments(0)


Be the first one to add a comment

Your name (required):


Your email(required, will not be shown to the public):


Your sites URL (optional):


Your comments:



More Tutorials by Bruce W. Perry
Embedding MP3 audio file in a JSP
Embedding a QuickTime movie in a JSP
Getting HTTP Request Headers in a JSP
Using a DataSource from WebLogic in a JSP
Creating a JavaBean to Connect with Google API
Deploying an Individual JSP on Tomcat
Writing your first JSP page

More Tutorials in JSP
LifecycleException: service.getName(): "Catalina"; Protocol handler start failed: `java.net.BindException: Permission denied <null>:80
JSP Alert Example
JSP CheckBox Example
Uploading an Image to a Database using JSP
Uploading a file to a server using JSP
A JSP page that gets properties from a bean
The page Directive in JSP
The taglib, tag, include, attribute and the variable Directive in JSP
Declarations in JSP
Scriptlets and Expressions in JSP
Tag Libraries in JSP
The Request Object in JSP
The Response Object in JSP
The Out Object in JSP
The Session Object in JSP

More Latest News
Most Viewed Articles (in JSP )
JSP Example to connect to MS SQL database and retrieve records
JSP Program for display Date
What are the different scopes in JSP?
Sending Email using JSP
Uploading an Image to a Database using JSP
JSP Alert Example
Writing your first JSP page
JSP CheckBox Example
Example Using Initialization Parameters
Basic Servlet Structure
Arithmetic Evaluation Using the Expression Language in JSP
The Request Object in JSP
Tags using in jsp
Enable/Disable Scripting Elements in JSP
LifecycleException: service.getName(): "Catalina"; Protocol handler start failed: `java.net.BindException: Permission denied <null>:80
Most Emailed Articles (in JSP)
Tag libraries
What is JSP?
LifecycleException: service.getName(): "Catalina"; Protocol handler start failed: `java.net.BindException: Permission denied <null>:80
What is JSP?
Click to Activate and Use this control
Tags using in jsp
Introduction to JSP expression language
Disabling Scriptlets in JSP using web.xml
Cookies using JSP or Java Bean
Closing Windows
Frame Object
Retrieving a Portion of a String
Getting HTTP Request Headers in a JSP
Syntax For JSP Declaratives
JSP Program for display Date