Submit data fields using java program.

In java networking you can fill the form program and send data fields to server. server will treat them as usual. Only you need to get URLConnection object from URL object and write data fields to OutputStream got through URLConnection Object.
Example :
package net;
import java.net.*;
import java.io.*;
//sending form data 
public class Net1{
 public static void main(String ar[])throws Exception{
  URL url=new URL("http://localhost:8080/networking/serv1");
  URLConnection con=url.openConnection();
  con.setDoOutput(true);
  OutputStreamWriter out=new OutputStreamWriter(con.getOutputStream());
  
  out.write("t1=abc");
  out.write("&t2=123");
  out.close();
  InputStream in= con.getInputStream();
  while(true){
   int x=in.read();
   if(x==-1)break;
   System.out.print((char)x);
  }
  
 }
}

No comments:

Popular Posts