Write to a Web server in Java

Description

The following code shows how to write to a Web server.

Example


/*from www  . jav a  2  s  .c o m*/
  
import java.io.PrintWriter;
import java.net.URL;
import java.net.URLConnection;

public class Main {
  public static void main(String[] a)throws Exception {

    URL url = new URL("http://www.yourdomain.com/form.jsp");
    URLConnection connection = url.openConnection();
    connection.setDoOutput(true);
    PrintWriter out = new PrintWriter(connection.getOutputStream());
    out.println("firstName=Jack");
    out.println("lastName=Yii");
    out.close();

  }

}




















Home »
  Java Tutorial »
    Network »




NetworkInterface
URI
URL
HTTP
HTTP Read
IP
Socket
UDP
URL Encode