• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

All you guru's. There must be a way to do this... Please help..........

 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
While I'm not a guru, how about


[This message has been edited by Marilyn deQueiroz (edited September 07, 2001).]
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

if ( con == null )
{
System.out.println( con.getURL() );
}
What?
getURL() on a null object...
- satya
 
Ranch Hand
Posts: 236
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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


oops
I fixed it.
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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

- satya
 
Manjunath Subramanian
Ranch Hand
Posts: 236
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for all your help guys. I now have a few ideas to be getting on with.
 
This parrot is no more. It has ceased to be. Now it's a tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic