Hi I want to re use the same HttpURLConnection instance to send different request to the same Servlet, does any body know how to do that?
here is my testing code: URL url = new URL("http://localhost:8080/test/echo"); HttpURLConnection connection = (HttpURLConnection)url.openConnection (); connection.setDoInput(true); connection.setDoOutput(true); connection.setUseCaches(false); connection.setRequestMethod("POST"); connection.setRequestProperty("Content-Type", "application/x- www-form-urlencoded"); connection.setRequestProperty("Connection", "Keep-Alive"); connection.setAllowUserInteraction(true); connection.connect(); OutputStream out = connection.getOutputStream(); DataOutputStream writer = new DataOutputStream(out); StringBuffer sb = new StringBuffer(); sb.append("sql=" + URLEncoder.encode("select name from category where rownum<2","utf-8")); writer.writeBytes(sb.toString()); writer.flush(); InputStream is = null; BufferedReader reader = null; String l = null; is = connection.getInputStream(); reader = new BufferedReader(new InputStreamReader(is)); while((l = reader.readLine())!= null){ System.out.println(l); } System.out.println("\n Sleep 3 seconds"); Thread.sleep(3000); sb = new StringBuffer(); sb.append("sql=" + URLEncoder.encode("select name from project where rownum<2","utf-8")); writer.writeBytes(sb.toString()); writer.flush(); while((l = reader.readLine())!= null){ System.out.println(l); } connection.disconnect(); The problem I got here was that the second request can not be sent to Servlet, the response from Servlet is only for the first request. How can I send the second request to Servlet without connect it again? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Java EE (J2EE) Programming with Passion!" group. To post to this group, send email to java-ee-j2ee-programming-with-passion@googlegroups.com To unsubscribe from this group, send email to java-ee-j2ee-programming-with-passion+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/java-ee-j2ee-programming-with-passion?hl=en?hl=en -~----------~----~----~----~------~----~------~--~---