import java.net.*;
import java.io.*;
import java.nio.charset.StandardCharsets;
public class Main
{
public static void main(String[] args) throws Exception
{
if (args.length != 2)
{
System.err.println("Usage: java Main " + "http://<location of your servlet/script>" + " string_to_reverse");
System.exit(1);
}
String stringToReverse = URLEncoder.encode(args[1], StandardCharsets.UTF_8);
URI url = new URI(args[0]);
URLConnection connection = url.toURL().openConnection();
connection.setDoOutput(true);
try (OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream()))
{
writer.write("string=" + stringToReverse);
}
try (BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())))
{
String line;
while ((line = reader.readLine()) != null)
System.out.println(line);
}
}
}
I have doPost() in servlet and is running in the backgorund. when writer.write("string=" + stringToReverse); is closed. it send that to the server [java servlet]?