import java.io.*; import javax.servlet.*; import javax.servlet.http.*; import java.util.*; /** Shows all the request headers sent on this request. * Taken from Core Web Programming Java 2 Edition * from Prentice Hall and Sun Microsystems Press, * http://www.corewebprogramming.com/. * May be freely used or adapted. */ public class ShowRequestHeaders extends HttpServlet { private static final String DOCTYPE = ""; private static String headWithTitle(String title) { return(DOCTYPE + "\n" + "\n" + "
Header Name | Header Value"); Enumeration headerNames = request.getHeaderNames(); while(headerNames.hasMoreElements()) { String headerName = (String)headerNames.nextElement(); out.println(" |
---|---|
" + headerName); out.println(" | " + request.getHeader(headerName)); } out.println(" |
\n" +
" Adapted from Listing 19.12
" +
" in Core Web Programming Java\n" +
" (2nd ed.)" +
" By Marty Hall and Larry Brown\n" +
" Published by Prentice Hall and Sun Microsystems Press.\n" +
"ShowRequestHeaders.java
" + " Compare these headers (in servlets) to headers in the CGI" + " with env.cgi." + "
"); out.println(""); } /** Let the same servlet handle both GET and POST. */ public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doGet(request, response); } }