| Author |
All you guru's. There must be a way to do this... Please help..........
|
Eric Howell
Ranch Hand
Joined: Nov 26, 2000
Posts: 63
|
|
I wonder if someone could lend me a hand. In the following snippit of code I want to validate that I have connected to the correct URL. How can I do this. Hope someone can help me out as I fail to find away but feel that you must be able to do this. Thanks in advance
|
 |
Madhav Lakkapragada
Ranch Hand
Joined: Jun 03, 2000
Posts: 5040
|
|
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
|
Take a Minute, Donate an Hour, Change a Life
http://www.ashanet.org/workanhour/2006/?r=Javaranch_ML&a=81
|
 |
Marilyn de Queiroz
Sheriff
Joined: Jul 22, 2000
Posts: 9033
|
|
While I'm not a guru, how about [This message has been edited by Marilyn deQueiroz (edited September 07, 2001).]
|
JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
|
 |
Madhav Lakkapragada
Ranch Hand
Joined: Jun 03, 2000
Posts: 5040
|
|
if ( con == null ) { System.out.println( con.getURL() ); } What? getURL() on a null object... - satya
|
 |
Manjunath Subramanian
Ranch Hand
Joined: Jul 18, 2001
Posts: 236
|
|
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
|
|
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: 9033
|
|
What? getURL() on a null object... - satya
oops  I fixed it.
|
 |
Madhav Lakkapragada
Ranch Hand
Joined: Jun 03, 2000
Posts: 5040
|
|
Marilyn: I was just nitpicking......  I knew you had a typo or something.... - satya
|
 |
Manjunath Subramanian
Ranch Hand
Joined: Jul 18, 2001
Posts: 236
|
|
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(); } } } Hope this helps buddy,  Manjunath [This message has been edited by Manjunath Subramanian (edited September 07, 2001).]
|
 |
Eric Howell
Ranch Hand
Joined: Nov 26, 2000
Posts: 63
|
|
|
Thanks for all your help guys. I now have a few ideas to be getting on with.
|
 |
 |
|
|
subject: All you guru's. There must be a way to do this... Please help..........
|
|
|