|  |  |  | 
 
   Sophisticated servlets can use browser headers to tailor the returned page
to the browser.  For example, a high-quality site can detect a Palm Pilot
browser and simplify its site design to match the browser capabilities.
   Each browser request sends headers along with the URL.  The
headers include the browser type (User-Agent) and
language preferences (Accept-Language and Accept-Charset).  The
full list is in the official HTTP/1.1 spec, but those three are the most
important. Servlet and JSPs grab headers with request.getHeader. The following, like env.jsp in the examples, gets all the headers
and prints them.  Little "snoop" servlets like this are useful to see what
headers browsers are sending. 
   
  test.HeaderServlet.java
  
  | 
package test;
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class HeaderServlet extends HttpServlet {
  public void doGet(HttpServletRequest request,
                    HttpServletResponse response)
    throws IOException, ServletException
  {
    PrintWriter out = response.getWriter();
    out.println("<table>");
    Enumeration e = request.getHeaderNames();
    while (e.hasMoreElements()) {
      String name = (String) e.nextElement();
      out.println("<tr><td>" + name);
      out.println("<td>" + request.getHeader(name));
    }
    out.println("</table>");
  }
}
 |  
   
  | 
Connection       Keep-Alive 
User-Agent       Mozilla/4.74 [en] (X11; U; Linux 2.4.0-test1 i686) 
Host             localhost:8080 
Accept           image/gif, image/jpeg, image/pjpeg, image/png, */* 
Accept-Encoding  gzip 
Accept-Language  en 
Accept-Charset   iso-8859-1,*,utf-8 
Cookie           JSESSIONID=7tXlVCaALedCHHkdXy 
 |  
 
  | Copyright © 1998-2005 Caucho Technology, Inc. All rights reserved. Resin® is a registered trademark,
and HardCoretm and Quercustm are trademarks of Caucho Technology, Inc.
 |  |  |