Request header display in a jsp page

This is detailed jsp code that shows how to display request header information in a jsp page. When user request to the server, the request defines an object to provide client request information to a jsp.


 
Ads

Request header display in a jsp page

     

This is detailed jsp code that shows how to display request header information in a jsp page. When user request to the server, the request defines an object to provide client request information to a jsp. In this example, request_header_jsp.jsp is used to display header information on the page. Request object's getMethod() method returns request method type i.e. GET or POST and getHeaderNames() method returns header names as an enumeration which can be iterated to get each of them.

request_header_jsp.jsp

<HTML>
<HEAD>
    <TITLE>Information about request header</TITLE>
</HEAD>
<BODY bgcolor="#ffffcc">
  <font size="+3" color="green"><br>Welcome in www.roseindia.net !</font>
  <font size="+2" color="#7E354D"><br>Information about request header</font>
  <br>
    <TABLE style="background-color: #ECE5B6;" WIDTH="30%" border="1">
	<tr>
	    <th>method used to send request</th>
           <!-- getMethod() returns the name of the HTTP 
method with which this request was made,
	     for example, GET, POST, or PUT -->
	     <td><%= request.getMethod() %></td>
	</tr>
	<tr>
	    <th>URI of the request</th>
      	    <!-- getRequestURI() returns the part of this request's URL -->
	    <td><%= request.getRequestURI() %></td>
	</tr>
	<%
	 /*This method returns an enumeration of all the header names this 
          request contains.*/	    
         java.util.Enumeration names = request.getHeaderNames();
         while (names.hasMoreElements()) {
	 String hname = (String)names.nextElement();
	%>
	<tr>
	    <th> <%= hname %> </th>
     		<!-- This method returns the value of the 
specified request header as a String. -->
		<td><%= request.getHeader(hname) %></td>
	</tr>
   <%
        }
   %>
 </body> 
</html>

Save this code as a .jsp file named "request_header_jsp.jsp" in your application directory in Tomcat , 'user' for this example, and run this jsp page with url http://localhost:8080/user/request_header_jsp.jsp in address bar of the browser.

Download Source Code

Advertisements

Share on Google+Share on Google+

Request header display in a jsp page

Posted on: July 7, 2008 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Advertisements

 

Discuss: Request header display in a jsp page  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:2
Jisha Madhu
March 22, 2011
how to display response in request page?

My request page have three text boxes. Enter register number in the first box then click the submit button.This time shows the name and mark to display the second and third boxes by under the register number.
ani
September 12, 2011
headernames

what is header names.whats the function.can u briefly describe it.

Ads

 

Ads