source: nutchez-0.1/tomcat/webapps/examples/WEB-INF/classes/RequestHeaderExample.java @ 177

Last change on this file since 177 was 66, checked in by waue, 15 years ago

NutchEz - an easy way to nutch

File size: 3.0 KB
Line 
1/*
2* Licensed to the Apache Software Foundation (ASF) under one or more
3* contributor license agreements.  See the NOTICE file distributed with
4* this work for additional information regarding copyright ownership.
5* The ASF licenses this file to You under the Apache License, Version 2.0
6* (the "License"); you may not use this file except in compliance with
7* the License.  You may obtain a copy of the License at
8*
9*     http://www.apache.org/licenses/LICENSE-2.0
10*
11* Unless required by applicable law or agreed to in writing, software
12* distributed under the License is distributed on an "AS IS" BASIS,
13* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14* See the License for the specific language governing permissions and
15* limitations under the License.
16*/
17/* $Id: RequestHeaderExample.java 500674 2007-01-27 23:15:00Z markt $
18 *
19 */
20
21import java.io.*;
22import java.util.*;
23import javax.servlet.*;
24import javax.servlet.http.*;
25
26import util.HTMLFilter;
27
28/**
29 * Example servlet showing request headers
30 *
31 * @author James Duncan Davidson <duncan@eng.sun.com>
32 */
33
34public 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  // all links relative
55
56        // XXX
57        // making these absolute till we work out the
58        // addition of a PathInfo issue
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
Note: See TracBrowser for help on using the repository browser.