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 |
|
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 18 | import java.io.IOException;
|
| 19 | import java.io.PrintWriter;
|
| 20 | import java.util.ResourceBundle;
|
| 21 |
|
| 22 | import javax.servlet.ServletException;
|
| 23 | import javax.servlet.http.HttpServlet;
|
| 24 | import javax.servlet.http.HttpServletRequest;
|
| 25 | import javax.servlet.http.HttpServletResponse;
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 26 |
|
| 27 | import util.HTMLFilter;
|
| 28 |
|
| 29 | /**
|
| 30 | * Example servlet showing request information.
|
| 31 | *
|
| 32 | * @author James Duncan Davidson <duncan@eng.sun.com>
|
| 33 | */
|
| 34 |
|
| 35 | public class RequestInfoExample extends HttpServlet {
|
| 36 |
|
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 37 | private static final long serialVersionUID = 1L;
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 38 |
|
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 39 | private static final ResourceBundle RB = ResourceBundle.getBundle("LocalStrings");
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 40 |
|
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 41 | @Override
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 42 | 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 |
|
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 52 | String title = RB.getString("requestinfo.title");
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 53 | 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>");
|
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 73 | out.println(RB.getString("requestinfo.label.method"));
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 74 | out.println("</td><td>");
|
| 75 | out.println(HTMLFilter.filter(request.getMethod()));
|
| 76 | out.println("</td></tr><tr><td>");
|
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 77 | out.println(RB.getString("requestinfo.label.requesturi"));
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 78 | out.println("</td><td>");
|
| 79 | out.println(HTMLFilter.filter(request.getRequestURI()));
|
| 80 | out.println("</td></tr><tr><td>");
|
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 81 | out.println(RB.getString("requestinfo.label.protocol"));
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 82 | out.println("</td><td>");
|
| 83 | out.println(HTMLFilter.filter(request.getProtocol()));
|
| 84 | out.println("</td></tr><tr><td>");
|
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 85 | out.println(RB.getString("requestinfo.label.pathinfo"));
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 86 | out.println("</td><td>");
|
| 87 | out.println(HTMLFilter.filter(request.getPathInfo()));
|
| 88 | out.println("</td></tr><tr><td>");
|
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 89 | out.println(RB.getString("requestinfo.label.remoteaddr"));
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 90 | 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 |
|
刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 107 | @Override
|
Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 108 | public void doPost(HttpServletRequest request,
|
| 109 | HttpServletResponse response)
|
| 110 | throws IOException, ServletException
|
| 111 | {
|
| 112 | doGet(request, response);
|
| 113 | }
|
| 114 |
|
| 115 | }
|
| 116 |
|