日期:2014-05-17 浏览次数:20782 次
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
res.setContentType("text/html;charset=utf-8");
PrintWriter out = res.getWriter();
out.println("<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
out.println("<html>");
out.println("<head><title>A Servlet</title></head>");
out.println("<body>");
out.println("<p>客户端发送过来的HTTP请求头: </p>");
@SuppressWarnings("unchecked")
Enumeration<String> headerNames = req.getHeaderNames();
while (headerNames.hasMoreElements()) {
String headerName = (String) headerNames.nextElement();
String headerValue = req.getHeader(headerName);
out.print("<b>" + headerName + "</b>");
out.println(headerValue + "</br>");
}
out.println("</body>");
out.println("</html>");
out.flush();
out.close();
}