Hi

The Servlet servers to execute any SQL and writes result back, so the
request maybe a very complicated SQL, that is why the POST method
should be used, because there is a limitation of the GET method on the
length of request.

And it is possible that clients access the Servlet very frequently, so
try to re use the same HttpURLConnection or Socket connection will
reduce the response time.

Since Connection: Keep-Alive header is available in HTTP 1.1, which
means it supports long connection, so it should be possible to keep
the Socket connection or HttpURLConnection open, and send multiple
requests using it. I tested using the Socket to send standard HTTP
headers, it was the same.

here is the testing code using Socket:

               Socket st = new Socket("localhost", 8080);
               st.setKeepAlive(true);
               OutputStream out = st.getOutputStream();
               BufferedWriter writer = new BufferedWriter(new
OutputStreamWriter(out));
               InputStream is = null;
               BufferedReader reader = null;
               String l = null;

               writer.write("GET /test/echo?sql=abc HTTP/1.1\r\n");
               writer.write("Host:localhost\r\n");
               writer.write("Connection:Keep-Alive\r\n");
               writer.write("\r\n");
               writer.flush();

               is = st.getInputStream();
               reader = new BufferedReader(new InputStreamReader(is));
               l = null;
               while((l = reader.readLine())!= null){
                     System.out.println("" + l);
               }

               System.out.println("\n Sleep 3 seconds");
               Thread.sleep(3000);

               writer.write("GET /test/echo?sql=def HTTP/1.1\r\n");
               writer.write("Host:localhost\r\n");
               writer.write("Connection:Keep-Alive\r\n");
               writer.write("\r\n");
               writer.flush();

               while((l = reader.readLine())!= null){
                      System.out.println("" + l);
               }

               st.close();

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to