I want to validate that I have connected to the correct URL What kinda validation are you talking abt? wether the URL is available and doesn't give a 404 Not found error or something else... please let us know a little more. regds. - satya

Hi Eric, What kind of validation are you talking about? Is it something like opening a connection to a URL and downloading and processing the contents or is it something else? Other wise this is a question more or less related to I/O!! Manjunath

Eric Howell
Ranch Hand

Joined: Nov 26, 2000
Posts: 63

posted Sep 07, 2001 13:40:00

0

Originally posted by Manjunath Subramanian: Hi Eric, What kind of validation are you talking about? Is it something like opening a connection to a URL and downloading and processing the contents or is it something else? Other wise this is a question more or less related to I/O!! Manjunath

Hi Manjunath The validation I'em after is that I have connected to the actual URL (as given in a form field on submission). Its for a URL portlal and I want to get some information from the HTML of the given URL- not from the HTML of the error page. At the moment I'em catching exeptions and doing it like that. Basically-validation I have connected to the correct URL-eg that it in fact exists. Hope you can understand my explanation Manjunath. Thanks for your help

Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9056

12

posted Sep 07, 2001 14:44:00

0

What?getURL() on a null object... - satya

oops I fixed it.

Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040

posted Sep 07, 2001 15:33:00

0

Marilyn: I was just nitpicking...... I knew you had a typo or something....

- satya

Manjunath Subramanian
Ranch Hand

Joined: Jul 18, 2001
Posts: 236

posted Sep 07, 2001 23:21:00

0

Hello Eric, If i am right in getting what you are trying to say then i think the little code i have written below should help you.What this program does is tries to open a URL stream on a valid URL and downloads the html onto a file and at the same time displaying the same on the command prompt window. import java.net.*; import java.io.*; public class Yahoo{ public static void main(String a[]) throws Exception {InputStream is = null;BufferedOutputStream br = new BufferedOutputStream(new FileOutputStream("yahoo.html")); try{ URL u = new URL("http://www.yahoo.com/index.html"); if( u.openConnection() != null) { is = u.openStream(); int i = (int)is.read(); while(i != -1) { br.write(i); System.out.print((char)i); br.flush(); i = (int)is.read(); } } else { System.out.println("Not a valid connection"); } } catch(Exception e) { e.printStackTrace(); } } }