blob: 86313e5b33785c726f62446ac33c7c3b5773b1b0 [file] [log] [blame]
Hongqing Liufd5ee812014-05-10 16:32:51 +08001/*
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
18import java.io.*;
19import java.util.*;
20import javax.servlet.*;
21import javax.servlet.http.*;
22
23import util.HTMLFilter;
24
25/**
26 * Example servlet showing request information.
27 *
28 * @author James Duncan Davidson <duncan@eng.sun.com>
29 */
30
31public class RequestInfoExample extends HttpServlet {
32
33
34 ResourceBundle rb = ResourceBundle.getBundle("LocalStrings");
35
36 public void doGet(HttpServletRequest request,
37 HttpServletResponse response)
38 throws IOException, ServletException
39 {
40 response.setContentType("text/html");
41
42 PrintWriter out = response.getWriter();
43 out.println("<html>");
44 out.println("<head>");
45
46 String title = rb.getString("requestinfo.title");
47 out.println("<title>" + title + "</title>");
48 out.println("</head>");
49 out.println("<body bgcolor=\"white\">");
50
51 // img stuff not req'd for source code html showing
52 // all links relative!
53
54 // XXX
55 // making these absolute till we work out the
56 // addition of a PathInfo issue
57
58 out.println("<a href=\"../reqinfo.html\">");
59 out.println("<img src=\"../images/code.gif\" height=24 " +
60 "width=24 align=right border=0 alt=\"view code\"></a>");
61 out.println("<a href=\"../index.html\">");
62 out.println("<img src=\"../images/return.gif\" height=24 " +
63 "width=24 align=right border=0 alt=\"return\"></a>");
64
65 out.println("<h3>" + title + "</h3>");
66 out.println("<table border=0><tr><td>");
67 out.println(rb.getString("requestinfo.label.method"));
68 out.println("</td><td>");
69 out.println(HTMLFilter.filter(request.getMethod()));
70 out.println("</td></tr><tr><td>");
71 out.println(rb.getString("requestinfo.label.requesturi"));
72 out.println("</td><td>");
73 out.println(HTMLFilter.filter(request.getRequestURI()));
74 out.println("</td></tr><tr><td>");
75 out.println(rb.getString("requestinfo.label.protocol"));
76 out.println("</td><td>");
77 out.println(HTMLFilter.filter(request.getProtocol()));
78 out.println("</td></tr><tr><td>");
79 out.println(rb.getString("requestinfo.label.pathinfo"));
80 out.println("</td><td>");
81 out.println(HTMLFilter.filter(request.getPathInfo()));
82 out.println("</td></tr><tr><td>");
83 out.println(rb.getString("requestinfo.label.remoteaddr"));
84 out.println("</td><td>");
85 out.println(HTMLFilter.filter(request.getRemoteAddr()));
86 out.println("</td></tr>");
87
88 String cipherSuite=
89 (String)request.getAttribute("javax.servlet.request.cipher_suite");
90 if(cipherSuite!=null){
91 out.println("<tr><td>");
92 out.println("SSLCipherSuite:");
93 out.println("</td><td>");
94 out.println(HTMLFilter.filter(cipherSuite));
95 out.println("</td></tr>");
96 }
97
98 out.println("</table>");
99 }
100
101 public void doPost(HttpServletRequest request,
102 HttpServletResponse response)
103 throws IOException, ServletException
104 {
105 doGet(request, response);
106 }
107
108}
109