Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Try It Free
Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old January 29th, 2002, 12:07 AM
pba311vw pba311vw is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2002
Posts: 0 pba311vw User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question sending out a get request to another page

I want to do some real distributed computing.

lets say i want to get a book price from barnesandnoble.com, i know that by going to URL i can get information on the book referred to by isbn=0062514792 such as the listed price.

now using AOLserver and the Tcl API, i can use the ns_httpget procedure which grabs info off a foreign server such as:

ns_httpget "http://www.census.gov/cgi-bin/popclock"

however I am using JSP and would like to get the same effect.

If anyone has any ideas for acheving this goal please enlighten me.

thanks,
-phil

Reply With Quote
  #2  
Old January 31st, 2002, 12:40 PM
pba311vw pba311vw is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2002
Posts: 0 pba311vw User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
in case anyone cares.....
i found a way to do it in Java
the following is some sample code:
<%
// if i want to get the present price of a book with isbn number
//0062514792 from barnesandnoble.com i would do the collowing
//in my JSP page

String url = "http://shop.barnesandnoble.com/bookSearch/isbnInquiry.asp?isbn=0062514792";

URL u = null;
HttpURLConnection urlc = null;

// Open a connection to a specified URL
try {
u = new URL (url);
}
catch (MalformedURLException mfurle) {
System.err.println ("URL: " + url + "\t\tMalformed URL " + mfurle.getMessage());
}
catch (Exception e) {
System.err.println ("URL: " + url + "\t\tException: " + e.getMessage());
}


// create HttpURLConnection object and then connect to the page
try {
urlc = (HttpURLConnection)u.openConnection ();
}
catch (UnknownHostException uhe) {
System.err.println (url + "\tUnknown Host " + uhe.getMessage());
}
catch (NoRouteToHostException nrthe) {
System.err.println (url + "\tNo Route to Host " + nrthe.getMessage());
}
catch (Exception e) {
System.err.println (url + "\tException " + e.getMessage());
}

// Define some HTTP header information about yourself
urlc.setRequestProperty ("User-Agent:", "just-a-test-v1.0");
urlc.setRequestProperty ("From:", "me@myaddress.edu");

// Now we can connect and start loading the page
try {
urlc.connect ();
}
catch (IOException ioe) {
System.err.println ("Connection Failure " + url + "\tException: " + ioe.getMessage());
}

// Load page contents using a buffered reader and the URLConnection.getInputStream()
// method. You should use this technique for first loading the robots.txt file for
// the site. If it exists, pay attention to it!
String line;
BufferedReader br = new BufferedReader (new InputStreamReader (urlc.getInputStream ()));
while ( (line = br.readLine ()) != null ) {
if (line.trim().startsWith("Our Price:")){
out.write("TRUE\n");
out.write(line+"\n");
}
}

// Close the stream when you're done, and then disconnect
br.close ();
urlc.disconnect ();

%>

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > sending out a get request to another page


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway