#how thing processed.

1 messages · Page 1 of 1 (latest)

somber lily
#
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]?

gilded boltBOT
#

<@&987246399047479336> please have a look, thanks.

narrow portal
#

If you're not going to use a http client then you should look into how these HTTP commands are to be formatted.