Connecting to a Servlet from a client application.

Hi,

I'm trying to connect to a servlet from a client application using the following code:

StringBuffer sb = new StringBuffer();

String str = "testing...";

sb.append("message=");

sb.append(java.net.URLEncoder.encode(str));

URL url = new URL("http://localhost:8080/servlet/ServerSmar");

connection = url.openConnection();

connection.setDoOutput(true);

connection.setRequestProperty ("Content-Type", "application/x-www-form-urlencoded");

PrintWriter out = new PrintWriter(

connection.getOutputStream());

out.print(sb.toString());

.....

,where connection is a URLConnection object.

I tested the Servlet from a Web Browser and it's running ok! But when I try to access from inside my application i get no answer! The service's servlet method is not called!

I would like to know how to solve this problem.

Thanks,

Davi

[939 byte] By [davicunha_] at [2007-9-27 13:52:54]
# 1
Try ading out.close(); once you've written the message to out. This will flush the output stream and let the servlet container know it has the complete request.
marmstrong at 2007-7-5 21:41:59 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...