001 /* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 /* $Id: RequestHeaderExample.java 514091 2007-03-03 06:26:39Z jdillon $ 018 * 019 */ 020 021 import java.io.*; 022 import java.util.*; 023 import javax.servlet.*; 024 import javax.servlet.http.*; 025 026 import util.HTMLFilter; 027 028 /** 029 * Example servlet showing request headers 030 * 031 * @author James Duncan Davidson <duncan@eng.sun.com> 032 */ 033 034 public class RequestHeaderExample extends HttpServlet { 035 036 ResourceBundle rb = ResourceBundle.getBundle("LocalStrings"); 037 038 public void doGet(HttpServletRequest request, 039 HttpServletResponse response) 040 throws IOException, ServletException 041 { 042 response.setContentType("text/html"); 043 044 PrintWriter out = response.getWriter(); 045 out.println("<html>"); 046 out.println("<body bgcolor=\"white\">"); 047 out.println("<head>"); 048 049 String title = rb.getString("requestheader.title"); 050 out.println("<title>" + title + "</title>"); 051 out.println("</head>"); 052 out.println("<body>"); 053 054 // all links relative 055 056 // XXX 057 // making these absolute till we work out the 058 // addition of a PathInfo issue 059 060 out.println("<a href=\"../reqheaders.html\">"); 061 out.println("<img src=\"../images/code.gif\" height=24 " + 062 "width=24 align=right border=0 alt=\"view code\"></a>"); 063 out.println("<a href=\"../index.html\">"); 064 out.println("<img src=\"../images/return.gif\" height=24 " + 065 "width=24 align=right border=0 alt=\"return\"></a>"); 066 067 out.println("<h3>" + title + "</h3>"); 068 out.println("<table border=0>"); 069 Enumeration e = request.getHeaderNames(); 070 while (e.hasMoreElements()) { 071 String headerName = (String)e.nextElement(); 072 String headerValue = request.getHeader(headerName); 073 out.println("<tr><td bgcolor=\"#CCCCCC\">"); 074 out.println(HTMLFilter.filter(headerName)); 075 out.println("</td><td>"); 076 out.println(HTMLFilter.filter(headerValue)); 077 out.println("</td></tr>"); 078 } 079 out.println("</table>"); 080 } 081 082 public void doPost(HttpServletRequest request, 083 HttpServletResponse response) 084 throws IOException, ServletException 085 { 086 doGet(request, response); 087 } 088 089 } 090