Java Reference
In-Depth Information
The StringBuffer contents are returned on line 466 on the previous page as a
String consisting of one line of comma-delimited results per requested stock. In
lines 136 and 137 (Figure 12-26 on page 809), this String is set as the session
attribute, quote, which is used by the JavaServer Page, mainForm.jsp, to display
the stock quote. To see the data returned by the service, you can enter the URL
in the address text box of a browser, and the returned comma-delimited text is
displayed in the browser window.
Viewing Stock Web Service Data
Because the Yahoo! stock quote service returns text, you can view
the returned data in a Web browser. To do so, type the URL and
corresponding parameters in the address box of your Web
browser and then press the ENTER key. For example, type
http://quote.yahoo.com/d/quotes
.csv?symbols=BA&format=sl1d1t1c1ohgv&ext=csv
to get a quote for stock BA. You can replace this symbol with
another valid stock symbol, or with multiple symbols separated by
commas. Be sure they are enclosed within a single set of quota-
tion marks. To see the results returned for an invalid stock, type
http://quote.yahoo.com/d/quotes
.csv?symbols=yy&format=sl1d1t1c1ohgv&ext=csv
The following step enters the code to acquire data from a Web service.
To Acquire Data from a Web Service
1. Click the Save button. Enter lines 439 through 468 as shown in
Figure 12-37 on the previous page.
TextPad displays the code to obtain data from the Yahoo! stock quote
Web service (Figure 12-38).
new URL to
Yahoo! stock
quote Web service
getQuote()
method
openConnection() method
connect()
method
FIGURE 12-38
 
Search WWH ::




Custom Search