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, java.io.IOException {
//get an Enumeration of all the request header names
Enumeration e = request.getHeaderNames();
//display
response.setContentType("text/html");
java.io.PrintWriter 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>");
}
out.println("</body></html>");
} //end doGet
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, java.io.IOException {
doGet(request, response);
}
}
|