1 2 24 25 26 27 28 package com.lutris.applet; 29 30 import java.applet.Applet ; 31 import java.io.IOException ; 32 import java.net.MalformedURLException ; 33 import java.net.URL ; 34 import java.net.URLConnection ; 35 37 55 public class LBSConnection { 56 57 public static final String nameParamName = "cookieName"; 58 public static final String valueParamName = "cookieValue"; 59 public static final String targetParamName = "targetURL"; 60 61 64 private LBSConnection() { 65 } 66 67 91 public static URLConnection contactServer(Applet applet) { 92 95 String targetURL = applet.getParameter(targetParamName); 96 System.out.println("target = " + targetURL); 97 if (targetURL == null) 98 return null; 99 String cookieName = applet.getParameter(nameParamName); 100 System.out.println("name = " + cookieName); 101 String cookieValue = applet.getParameter(valueParamName); 102 System.out.println("value = " + cookieValue); 103 106 URL url = null; 107 try { 108 url = new URL (targetURL); 109 } catch (MalformedURLException e) { 110 System.out.println("bad url!"); 111 return null; 112 } 113 URLConnection conn = null; 114 try { 115 conn = url.openConnection(); 116 System.out.println("conn = " + conn); 117 } catch (IOException e) { 118 System.out.println("io err"); 119 return null; 120 } catch (ClassCastException e) { 121 System.out.println("class cast err"); 122 return null; 123 } catch (Throwable e) { 124 System.out.println("threw " + e); 125 return null; 126 } 127 128 129 133 if ((cookieName != null) && (cookieValue != null)) 134 conn.setRequestProperty("Cookie", cookieName + "=" + cookieValue); 135 139 return conn; 140 } 141 142 } 143 144 | Popular Tags |