blob: 1f429e8e4f43e94b540b75c124d28b01d47841dc [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
刘洪青6266f992017-05-15 21:21:03 +080018import java.io.IOException;
19import java.io.PrintWriter;
20import java.util.ResourceBundle;
21
22import javax.servlet.ServletException;
23import javax.servlet.http.HttpServlet;
24import javax.servlet.http.HttpServletRequest;
25import javax.servlet.http.HttpServletResponse;
Hongqing Liufd5ee812014-05-10 16:32:51 +080026
27import util.HTMLFilter;
28
29/**
30 * Example servlet showing request information.
31 *
32 * @author James Duncan Davidson <duncan@eng.sun.com>
33 */
34
35public class RequestInfoExample extends HttpServlet {
36
刘洪青6266f992017-05-15 21:21:03 +080037 private static final long serialVersionUID = 1L;
Hongqing Liufd5ee812014-05-10 16:32:51 +080038
刘洪青6266f992017-05-15 21:21:03 +080039 private static final ResourceBundle RB = ResourceBundle.getBundle("LocalStrings");
Hongqing Liufd5ee812014-05-10 16:32:51 +080040
刘洪青6266f992017-05-15 21:21:03 +080041 @Override
Hongqing Liufd5ee812014-05-10 16:32:51 +080042 public void doGet(HttpServletRequest request,
43 HttpServletResponse response)
44 throws IOException, ServletException
45 {
46 response.setContentType("text/html");
47
48 PrintWriter out = response.getWriter();
49 out.println("<html>");
50 out.println("<head>");
51
刘洪青6266f992017-05-15 21:21:03 +080052 String title = RB.getString("requestinfo.title");
Hongqing Liufd5ee812014-05-10 16:32:51 +080053 out.println("<title>" + title + "</title>");
54 out.println("</head>");
55 out.println("<body bgcolor=\"white\">");
56
57 // img stuff not req'd for source code html showing
58 // all links relative!
59
60 // XXX
61 // making these absolute till we work out the
62 // addition of a PathInfo issue
63
64 out.println("<a href=\"../reqinfo.html\">");
65 out.println("<img src=\"../images/code.gif\" height=24 " +
66 "width=24 align=right border=0 alt=\"view code\"></a>");
67 out.println("<a href=\"../index.html\">");
68 out.println("<img src=\"../images/return.gif\" height=24 " +
69 "width=24 align=right border=0 alt=\"return\"></a>");
70
71 out.println("<h3>" + title + "</h3>");
72 out.println("<table border=0><tr><td>");
刘洪青6266f992017-05-15 21:21:03 +080073 out.println(RB.getString("requestinfo.label.method"));
Hongqing Liufd5ee812014-05-10 16:32:51 +080074 out.println("</td><td>");
75 out.println(HTMLFilter.filter(request.getMethod()));
76 out.println("</td></tr><tr><td>");
刘洪青6266f992017-05-15 21:21:03 +080077 out.println(RB.getString("requestinfo.label.requesturi"));
Hongqing Liufd5ee812014-05-10 16:32:51 +080078 out.println("</td><td>");
79 out.println(HTMLFilter.filter(request.getRequestURI()));
80 out.println("</td></tr><tr><td>");
刘洪青6266f992017-05-15 21:21:03 +080081 out.println(RB.getString("requestinfo.label.protocol"));
Hongqing Liufd5ee812014-05-10 16:32:51 +080082 out.println("</td><td>");
83 out.println(HTMLFilter.filter(request.getProtocol()));
84 out.println("</td></tr><tr><td>");
刘洪青6266f992017-05-15 21:21:03 +080085 out.println(RB.getString("requestinfo.label.pathinfo"));
Hongqing Liufd5ee812014-05-10 16:32:51 +080086 out.println("</td><td>");
87 out.println(HTMLFilter.filter(request.getPathInfo()));
88 out.println("</td></tr><tr><td>");
刘洪青6266f992017-05-15 21:21:03 +080089 out.println(RB.getString("requestinfo.label.remoteaddr"));
Hongqing Liufd5ee812014-05-10 16:32:51 +080090 out.println("</td><td>");
91 out.println(HTMLFilter.filter(request.getRemoteAddr()));
92 out.println("</td></tr>");
93
94 String cipherSuite=
95 (String)request.getAttribute("javax.servlet.request.cipher_suite");
96 if(cipherSuite!=null){
97 out.println("<tr><td>");
98 out.println("SSLCipherSuite:");
99 out.println("</td><td>");
100 out.println(HTMLFilter.filter(cipherSuite));
101 out.println("</td></tr>");
102 }
103
104 out.println("</table>");
105 }
106
刘洪青6266f992017-05-15 21:21:03 +0800107 @Override
Hongqing Liufd5ee812014-05-10 16:32:51 +0800108 public void doPost(HttpServletRequest request,
109 HttpServletResponse response)
110 throws IOException, ServletException
111 {
112 doGet(request, response);
113 }
114
115}
116