Request header viewer : Do Get Do Post « Servlets « Java

Request header viewer

import java.util.Enumeration;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class RequestHeaderView extends HttpServlet {

  public void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, {

    //get an Enumeration of all the request header names
    Enumeration e = request.getHeaderNames();

    response.setContentType("text/html"); out = response.getWriter();
    out.println("<html><head><title>Request Header View</title></head><body>");
    out.println("<h2>Request Headers</h2>");
    String header = null;

    while (e.hasMoreElements()) {
      header = (String) e.nextElement();
      //getHeader returns null if a request header of that name does not
      // exist in the request
      out.println("<strong>" + header + "</strong>" + ": "
          + request.getHeader(header) + "<br>");


  } //end doGet

  public void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, {
    doGet(request, response);



Related examples in the same category

1.Simple servlet: Copyright
2.Print various CGI variables that have been requested by the servlet
3.Print all header information available from the client
4.Request binder
5.Request display
6.Servlet Request Listener
7.Client auto refresh
8.Get Request Parameters in a Servlet