answersLogoWhite

0


Best Answer

Retrieving HTTP Request Header Information

The Http Request header is the area where all the details of the request are bundled. This is where the browser specifies the file wanted, date, image file support, and a lot more. Let us take a look at a sample Servlet that is going to read through the Http Request Header.

Servlet code:

import java.io.*;

import java.text.*;

import java.util.*;

import javax.servlet.*;

import javax.servlet.http.*;

/**

* Displaying request headers

*

* @author Anand V

*/

public class ReadHttpRequestHeaderServlet extends HttpServlet {

public void doGet(HttpServletRequest request, HttpServletResponse response)

throws IOException, ServletException

{

response.setContentType("text/HTML");

PrintWriter out = response.getWriter();

out.println("< HTML >");

out.println("< head >");

String title = "Read Request Header Example";

out.println("< title >" + title + "");

out.println("< / head >");

out.println("< body >");

out.println("< h3 >" + title + "< / h3 >");

out.println("< table >");

Enumeration e = request.getHeaderNames();

while (e.hasMoreElements())

{

String headerName = (String)e.nextElement();

String headerValue = request.getHeader(headerName);

out.println("< tr >< td bgcolor="#CCCCCC" > " + headerName);

out.println("< / td >< td > " + headerValue + " < / td > < / tr >");

}

out.println("< / table >");

out.println("< / body >");

out.println("< / HTML >");

}

}

User Avatar

Wiki User

12y ago
This answer is:
User Avatar
More answers
User Avatar

AnswerBot

3d ago

You can create a servlet that overrides the doGet method to access the request headers using the HttpServletRequest object. You can then iterate through the headers and display them as needed. Be sure to set the appropriate content type before writing the response to the HttpServletResponse object.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a servlet to display request header information?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is the purpose of inserting header and footer in document?

The header and footer in a document are very important. These notes can give the reader more information about the document they are reading.


How do you display a documents header in an editable format?

Simply double-click in the area where the header belongs. The header will appear &amp; you can edit from there. Hope this helps!


What is used to display column headings?

header row


Where does The form header section display?

At the top of each form.


What are three common HTTP message types?

REQUEST HEADER


What is the default styling for h1 HTML tag?

The H1 tag is used to display Headings in HTML. &lt;H1&gt; Hi this is a H1 header &lt;/H1&gt; would display like = Hi this is a H1 header =


What is the use of DOS header files in graphics?

It shows the header information..


What Contains information about an email message such as sender time sent and subject?

Message Header


What information goes in a resume header?

Applicant's personal contact information


Different text control tags?

Some Text control tags are * &lt;FONT&gt; to decide the display font * &lt;B&gt; to display text in Bold * &lt;I&gt; to display text in Italics * &lt;H1&gt; to &lt;H6&gt; to display text in header format * etc...


What is headerfile?

who hold the header information is called headerfile.


What is found on a datalink layer header?

The data link layer header contains the destination and source of information of the original frame and device sending information. You will also find that it contains the information of the device to receive it.