1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 import java.io.*;
21 import java.text.*;
22 import java.util.*;
23 import javax.servlet.*;
24 import javax.servlet.http.*;
25
26 import util.HTMLFilter;
27
28 /**
29 * Example servlet showing request headers
30 *
31 * @author James Duncan Davidson <duncan@eng.sun.com>
32 */
33
34 public class RequestHeaderExample extends HttpServlet {
35
36 ResourceBundle rb = ResourceBundle.getBundle("LocalStrings");
37
38 public void doGet(HttpServletRequest request,
39 HttpServletResponse response)
40 throws IOException, ServletException
41 {
42 response.setContentType("text/html");
43
44 PrintWriter out = response.getWriter();
45 out.println("<html>");
46 out.println("<body bgcolor=\"white\">");
47 out.println("<head>");
48
49 String title = rb.getString("requestheader.title");
50 out.println("<title>" + title + "</title>");
51 out.println("</head>");
52 out.println("<body>");
53
54
55
56
57
58
59
60 out.println("<a href=\"../reqheaders.html\">");
61 out.println("<img src=\"../images/code.gif\" height=24 " +
62 "width=24 align=right border=0 alt=\"view code\"></a>");
63 out.println("<a href=\"../index.html\">");
64 out.println("<img src=\"../images/return.gif\" height=24 " +
65 "width=24 align=right border=0 alt=\"return\"></a>");
66
67 out.println("<h3>" + title + "</h3>");
68 out.println("<table border=0>");
69 Enumeration e = request.getHeaderNames();
70 while (e.hasMoreElements()) {
71 String headerName = (String)e.nextElement();
72 String headerValue = request.getHeader(headerName);
73 out.println("<tr><td bgcolor=\"#CCCCCC\">");
74 out.println(HTMLFilter.filter(headerName));
75 out.println("</td><td>");
76 out.println(HTMLFilter.filter(headerValue));
77 out.println("</td></tr>");
78 }
79 out.println("</table>");
80 }
81
82 public void doPost(HttpServletRequest request,
83 HttpServletResponse response)
84 throws IOException, ServletException
85 {
86 doGet(request, response);
87 }
88
89 }
90