1 package cli; 2 3 import java.io.*; 4 import java.net.HttpURLConnection ; 5 import java.net.URL ; 6 7 public class HelloClient { 8 9 public static void main(String [] args) { 10 try { 11 callServlet(); 12 } catch (Exception e) { 13 e.printStackTrace(); 14 } 15 } 16 17 private static void callServlet() throws IOException { 18 URL url = new URL ("http", "localhost", 80, "/SimpleOzoneServlet/HelloServlet"); 19 System.out.println("Connecting to " + url); 20 HttpURLConnection connection = (HttpURLConnection ) url.openConnection(); 21 BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); 22 String response = reader.readLine(); 23 do { 24 System.out.println(response); 25 response = reader.readLine(); 26 } while (response != null); 27 } 28 } | Popular Tags |