Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Java
Expertise: Advanced
Feb 20, 2001

Reading From and Writing To a URL


A typical HTML page might contain text fields to send data to the server. The data is submitted by clicking the submit button on the Web page. The browser then writes the data to the URL over the network. The same thing came be done in a Java program using the URL class in java.net package. To do this, you need an open connection to the URL. A connection can be opened by using the openConnection() method in the URL class. Using the following code, you can write information to a site directly without the help of the browser:
 
import java.io.*;
import java.net.*;

public class Submit {
    public static void main(String[] args) throws Exception
	{
           String data=URLEncoder.encode(args[0]);
           URL url = new URL(
M.V. Prem
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date