An example from here :
import java.net.*; import java.io.*; public class URLConnectionReader { public static void main(String[] args) throws Exception { URL yahoo = new URL("http://www.yahoo.com/"); URLConnection yc = yahoo.openConnection(); BufferedReader in = new BufferedReader( new InputStreamReader( yc.getInputStream())); String inputLine; while ((inputLine = in.readLine()) != null) System.out.println(inputLine); in.close(); } }
From your point of view, a servlet is just a URL on some server. As for not expecting an answer, read about Java threads. But you cannot close the HTTP connection without waiting for the servlet to complete, as this may cause the servlet to fail. Just wait for the response in a separate thread and discard it if it does not matter.
source share