Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame^] | 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 |
|
| 18 | import java.io.*;
|
| 19 | import java.util.*;
|
| 20 | import javax.servlet.*;
|
| 21 | import javax.servlet.http.*;
|
| 22 |
|
| 23 | import util.HTMLFilter;
|
| 24 |
|
| 25 | /**
|
| 26 | * Example servlet showing request headers
|
| 27 | *
|
| 28 | * @author James Duncan Davidson <duncan@eng.sun.com>
|
| 29 | */
|
| 30 |
|
| 31 | public class RequestHeaderExample extends HttpServlet {
|
| 32 |
|
| 33 | ResourceBundle rb = ResourceBundle.getBundle("LocalStrings");
|
| 34 |
|
| 35 | public void doGet(HttpServletRequest request,
|
| 36 | HttpServletResponse response)
|
| 37 | throws IOException, ServletException
|
| 38 | {
|
| 39 | response.setContentType("text/html");
|
| 40 |
|
| 41 | PrintWriter out = response.getWriter();
|
| 42 | out.println("<html>");
|
| 43 | out.println("<head>");
|
| 44 |
|
| 45 | String title = rb.getString("requestheader.title");
|
| 46 | out.println("<title>" + title + "</title>");
|
| 47 | out.println("</head>");
|
| 48 | out.println("<body bgcolor=\"white\">");
|
| 49 |
|
| 50 | // all links relative
|
| 51 |
|
| 52 | // XXX
|
| 53 | // making these absolute till we work out the
|
| 54 | // addition of a PathInfo issue
|
| 55 |
|
| 56 | out.println("<a href=\"../reqheaders.html\">");
|
| 57 | out.println("<img src=\"../images/code.gif\" height=24 " +
|
| 58 | "width=24 align=right border=0 alt=\"view code\"></a>");
|
| 59 | out.println("<a href=\"../index.html\">");
|
| 60 | out.println("<img src=\"../images/return.gif\" height=24 " +
|
| 61 | "width=24 align=right border=0 alt=\"return\"></a>");
|
| 62 |
|
| 63 | out.println("<h3>" + title + "</h3>");
|
| 64 | out.println("<table border=0>");
|
| 65 | Enumeration e = request.getHeaderNames();
|
| 66 | while (e.hasMoreElements()) {
|
| 67 | String headerName = (String)e.nextElement();
|
| 68 | String headerValue = request.getHeader(headerName);
|
| 69 | out.println("<tr><td bgcolor=\"#CCCCCC\">");
|
| 70 | out.println(HTMLFilter.filter(headerName));
|
| 71 | out.println("</td><td>");
|
| 72 | out.println(HTMLFilter.filter(headerValue));
|
| 73 | out.println("</td></tr>");
|
| 74 | }
|
| 75 | out.println("</table>");
|
| 76 | }
|
| 77 |
|
| 78 | public void doPost(HttpServletRequest request,
|
| 79 | HttpServletResponse response)
|
| 80 | throws IOException, ServletException
|
| 81 | {
|
| 82 | doGet(request, response);
|
| 83 | }
|
| 84 |
|
| 85 | }
|
| 86 |
|