KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > RequestInfoExample


1 /*
2 * Copyright 2004 The Apache Software Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */

16 /* $Id: RequestInfoExample.java,v 1.3 2006/10/12 14:31:28 abadea Exp $
17  *
18  */

19
20 import java.io.*;
21 import java.text.*;
22 import java.util.*;
23 import javax.servlet.*;
24 import javax.servlet.http.*;
25
26 import util.HTMLFilter;
27
28 /**
29  * Example servlet showing request information.
30  *
31  * @author James Duncan Davidson <duncan@eng.sun.com>
32  */

33
34 public class RequestInfoExample extends HttpServlet {
35
36
37     ResourceBundle rb = ResourceBundle.getBundle("LocalStrings");
38
39     public void doGet(HttpServletRequest request,
40                       HttpServletResponse response)
41         throws IOException, ServletException
42     {
43         response.setContentType("text/html");
44
45         PrintWriter out = response.getWriter();
46         out.println("<html>");
47         out.println("<body>");
48         out.println("<head>");
49
50         String JavaDoc title = rb.getString("requestinfo.title");
51         out.println("<title>" + title + "</title>");
52         out.println("</head>");
53         out.println("<body bgcolor=\"white\">");
54
55         // img stuff not req'd for source code html showing
56
// all links relative!
57

58         // XXX
59
// making these absolute till we work out the
60
// addition of a PathInfo issue
61

62         out.println("<a HREF=\"../reqinfo.html\">");
63         out.println("<img SRC=\"../images/code.gif\" height=24 " +
64                     "width=24 align=right border=0 alt=\"view code\"></a>");
65         out.println("<a HREF=\"../index.html\">");
66         out.println("<img SRC=\"../images/return.gif\" height=24 " +
67                     "width=24 align=right border=0 alt=\"return\"></a>");
68
69         out.println("<h3>" + title + "</h3>");
70         out.println("<table border=0><tr><td>");
71         out.println(rb.getString("requestinfo.label.method"));
72         out.println("</td><td>");
73         out.println(request.getMethod());
74         out.println("</td></tr><tr><td>");
75         out.println(rb.getString("requestinfo.label.requesturi"));
76         out.println("</td><td>");
77         out.println(HTMLFilter.filter(request.getRequestURI()));
78         out.println("</td></tr><tr><td>");
79         out.println(rb.getString("requestinfo.label.protocol"));
80         out.println("</td><td>");
81         out.println(request.getProtocol());
82         out.println("</td></tr><tr><td>");
83         out.println(rb.getString("requestinfo.label.pathinfo"));
84         out.println("</td><td>");
85         out.println(HTMLFilter.filter(request.getPathInfo()));
86         out.println("</td></tr><tr><td>");
87         out.println(rb.getString("requestinfo.label.remoteaddr"));
88
89     String JavaDoc cipherSuite=
90         (String JavaDoc)request.getAttribute("javax.servlet.request.cipher_suite");
91         out.println("</td><td>");
92         out.println(request.getRemoteAddr());
93         out.println("</table>");
94
95     if(cipherSuite!=null){
96         out.println("</td></tr><tr><td>");
97         out.println("SSLCipherSuite:");
98         out.println("</td>");
99         out.println("<td>");
100         out.println(request.getAttribute("javax.servlet.request.cipher_suite"));
101         out.println("</td>");
102     }
103     
104     }
105
106     public void doPost(HttpServletRequest request,
107                       HttpServletResponse response)
108         throws IOException, ServletException
109     {
110         doGet(request, response);
111     }
112
113 }
114
115
Popular Tags