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

1    package net.server.servlets; 
2     
3    import javax.servlet.ServletException; 
4    import javax.servlet.http.HttpServlet; 
5    import javax.servlet.http.HttpServletRequest; 
6    import javax.servlet.http.HttpServletResponse; 
7    import java.io.IOException; 
8    import java.io.PrintWriter; 
9     
10   public class ProxyServlet extends HttpServlet { 
11    
12       public void doGet(HttpServletRequest request, 
13                         HttpServletResponse response) 
14               throws IOException, ServletException { 
15           response.setContentType("text/html"); 
16           PrintWriter out = response.getWriter(); 
17           String url = request.getParameter("url"); 
18           if (url == null) { 
19               out.println(getForm()); 
20               return; 
21           } 
22           Proxy.print(Proxy.getUrl(url), out); 
23       } 
24    
25       public static String getForm() { 
26           return 
27                   "<HTML>" 
28                   + "<HEAD>" 
29                   + "   <TITLE>DocJavaProxy Server</TITLE>" 
30                   + "</HEAD>" 
31                   + "<BODY BGCOLOR=#FFFFFF>" 
32                   + "<FORM action=http://www.docjava.com:8080/examples/servlet/ProxyServlet " 
33                   + "method=GET>" 
34                   + "<P><B>Welcome to the DocJava Proxy Server</B></P>" 
35                   + "<P><B>This server is used for sites that require authentication to" 
36                   + " get out on</B></P>" 
37                   + "<P><B>port 80. </B></P>" 
38                   + "<P><B>enter a url:<INPUT TYPE=" 
39                   + "text NAME=url VALUE=http://www.docjava.com SIZE=90></B>" 
40                   + "</P>" 
41                   + "" 
42                   + "<P><B>CopyLeft 2001, DocJava, Inc.</B></P>" 
43                   + "</FORM>" 
44                   + "</BODY>" 
45                   + "</HTML>"; 
46       } 
47   } 
48    
49    
50    
51