/Users/lyon/j4p/src/net/server/servlets/RequestInfoExample.java

1    package net.server.servlets; 
2     
3    /* $Id: RequestInfoExample.java,v 1.2 1999/03/17 02:36:51 duncan Exp $ 
4     * 
5     */ 
6     
7    import javax.servlet.ServletException; 
8    import javax.servlet.http.HttpServlet; 
9    import javax.servlet.http.HttpServletRequest; 
10   import javax.servlet.http.HttpServletResponse; 
11   import java.io.IOException; 
12   import java.io.PrintWriter; 
13   import java.util.ResourceBundle; 
14    
15    
16   /** 
17    * Example servlet showing request information. 
18    * 
19    * @author James Duncan Davidson <duncan@eng.sun.com> 
20    */ 
21    
22   public class RequestInfoExample extends HttpServlet { 
23    
24    
25       ResourceBundle rb = ResourceBundle.getBundle("LocalStrings"); 
26    
27    
28       public void doGet(HttpServletRequest request, 
29                         HttpServletResponse response) 
30               throws IOException, ServletException { 
31           response.setContentType("text/html"); 
32    
33           PrintWriter out = response.getWriter(); 
34           out.println("<html>"); 
35           out.println("<body>"); 
36           out.println("<head>"); 
37    
38           String title = rb.getString("requestinfo.title"); 
39           out.println("<title>" + title + "</title>"); 
40           out.println("</head>"); 
41           out.println("<body bgcolor=\"white\">"); 
42    
43           // img stuff not req'd for source code html showing 
44           // all links relative! 
45    
46           out.println("<a href=\"../servlets/reqinfo.html\">"); 
47           out.println("<img src=\"../images/code.gif\" height=24 " + 
48                   "width=24 align=right border=0 alt=\"view code\"></a>"); 
49           out.println("<a href=\"../servlets/index.html\">"); 
50           out.println("<img src=\"../images/return.gif\" height=24 " + 
51                   "width=24 align=right border=0 alt=\"return\"></a>"); 
52    
53           out.println("<h3>" + title + "</h3>"); 
54           out.println("<p>sw410</p>"); 
55           out.println("<table border=0><tr><td>"); 
56           out.println(rb.getString("requestinfo.label.method")); 
57           out.println("</td><td>"); 
58           out.println(request.getMethod()); 
59           out.println("</td></tr><tr><td>"); 
60           out.println(rb.getString("requestinfo.label.requesturi")); 
61           out.println("</td><td>"); 
62           out.println(request.getRequestURI()); 
63           out.println("</td></tr><tr><td>"); 
64           out.println(rb.getString("requestinfo.label.protocol")); 
65           out.println("</td><td>"); 
66           out.println(request.getProtocol()); 
67           out.println("</td></tr><tr><td>"); 
68           out.println(rb.getString("requestinfo.label.pathinfo")); 
69           out.println("</td><td>"); 
70           out.println(request.getPathInfo()); 
71           out.println("</td></tr><tr><td>"); 
72           out.println(rb.getString("requestinfo.label.remoteaddr")); 
73           out.println("</td><td>"); 
74           out.println(request.getRemoteAddr()); 
75           out.println("</table>"); 
76       } 
77    
78       public void doPost(HttpServletRequest request, 
79                          HttpServletResponse response) 
80               throws IOException, ServletException { 
81           doGet(request, response); 
82       } 
83    
84   } 
85    
86