/*
* PrintHeader
* PrintHeader
*
* PrintHeader
* /PrintHeader
*
*
*/
import java.io.IOException;
import java.io.PrintWriter;
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 PrintHeader extends HttpServlet {
/**
* doGet implementation, calls printHeader function
*
* @param request
* @param response
* @throws IOException
* @throws ServletException
*
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
printHeader(request, response);
}
/**
* doPost implementation, calls printHeader function
*
* @param request
* @param response
* @throws IOException
* @throws ServletException
*
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
printHeader(request, response);
}
/**
* Prints client header information that is available
*
* @param request
* @param response
* @throws IOException
* @throws ServletException
*
*/
public void printHeader(HttpServletRequest request,
HttpServletResponse response) throws IOException, ServletException {
String headers = null;
String htmlHeader = " Request Headers ";
String htmlFooter = "";
response.setContentType("text/html");
PrintWriter out = response.getWriter();
Enumeration e = request.getHeaderNames();
out.println(htmlHeader);
out.println("");
out.println(" Header Value ");
while (e.hasMoreElements()) {
headers = (String) e.nextElement();
if (headers != null) {
out.println("" + headers + " ");
out.println("" + request.getHeader(headers)
+ " ");
}
}
out.println("
");
out.println(htmlFooter);
}
}