Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading input from a HTML form

Status
Not open for further replies.

youngun

Programmer
Apr 27, 2001
61
US
I am a newbie to Internet programming using Java. I am trying to read in info from a html form running on UNIX (Apache). The problem is that I can not use servlet class. I read couple JSP articles and they also use servlet class. Is there any alternative way for me to get info using Java?

Thankx.
 
If you want to have a java program read a web page from a server, here is a simple snippet that will do it:

import java.util.*;
import java.text.*;
import java.net.*;
import java.io.*;

public class Test4
{
public Test4()
{
}

public static void main(String[] args)
{
Test4 t4 = new Test4();
t4.go();
}

public void go()
{
URLConnection conn = null;
DataInputStream data = null;
String line;
StringBuffer buf = new StringBuffer();

String url = " URL myurl = null;
try { myurl = new URL(url); }
catch ( MalformedURLException e) { System.err.println("Bad URL: " + myurl); }

try
{
System.err.println(&quot;Connecting to <&quot; + myurl.toString() + &quot;>&quot;);
conn = myurl.openConnection();
conn.connect();

System.err.println(&quot;Connection opened...&quot;);

data = new DataInputStream(new BufferedInputStream(conn.getInputStream()));

System.err.println(&quot;Reading data...&quot;);
while ((line = data.readLine()) != null)
{
buf.append(line + &quot;\n&quot;);
}

System.err.println(buf.toString());
data.close();
}
catch (IOException e)
{
System.err.println(&quot;IO Error:&quot; + e.getMessage());
}
catch (Exception ee)
{
System.err.println(&quot;Error:&quot; + ee.toString());
}

}
}
 
Thank you, idarke. I will try if it works.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top