RequestInfoExample.java
上传用户:bj_pst
上传日期:2019-07-07
资源大小:7353k
文件大小:4k
源码类别:

Java编程

开发平台:

Java

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