When you think ASP, think...
Recent Articles
All Articles
ASP.NET Articles
ASPFAQs.com
Message Board
Related Web Technologies
User Tips!
Coding Tips

Sections:
Sample Chapters
Commonly Asked Message Board Questions
JavaScript Tutorials
MSDN Communities Hub
Official Docs
Security
Stump the SQL Guru!
XML Info
Information:
Feedback
Author an Article
ASP ASP.NET ASP FAQs Message Board Feedback
Print this page.
Published: Wednesday, August 11, 1999

Using Java & ASP to Grab Stock Quotes
By Ian Stallings


In the last article we made a basic hello world Java object that we could interact with using ASP. If you have not read that article I recommend you check it out before reading further. This time we're going to really dig in and build a cool object that will grab a string on another site using the URL.

- continued -

Ok, First thing we do is create the .java source file. Hopefully this will help you pick up the Java syntax. For those of you that are familiar with Javascript it should be pretty easy. Please read the comments in the code to get a better understanding of Java.

The code for class is available in text format.

You then go to the command line again and compile the StringGrabber.java file just like we did the last one. Once that file is compiled place the StringGrabber.class file in the %Win%/Java/TrustLib directory. You can now access it from an ASP file.

Next, Let's create the ASP file using this VBscript:

<html>
<head>
</head>
<body>
<h2>StockGrabber Test</h2>

<%
Response.Write("<form action='stringgrabber.asp' method='post'>Stock Ticker Symbol:<br>")
Response.Write("<input type='text' name='ticker'><br>")
Response.Write("<input type='submit' value='submit'><br><br>")

If Request.Form("ticker") <> "" then
	strTicker = Request.Form("ticker")

	'Create a StringGrabber object.
	set StringGrabber = GetObject("java:StringGrabber")

	Response.Write(strTicker & GetStockPriceFromURL(strTicker)) 
End If


Function GetStockPriceFromURL(stockSymbol)

	preString = "<b>$"
	postString = "</b>"
	url = "http://quotes.nasdaq-amex.com/Quote.dll?page=multi&mode=Stock&symbol=" & stockSymbol

	stockPrice = StringGrabber.GetString(url, preString, postString)

	GetStockPriceFromURL = stockPrice
End Function
%>
</body>
</html>

This should go directly to Nasdaq's website and grab the newest stock price for the stock entered based on the ticker symbol. The string is found by parsing the web page and looking for the first <b>$ it finds. It then looks for the next </b> and take whatever's inbetween. This function can be altered greatly to get any string you want. Say the headlines from a news site, the weather, etc. You can change the web page it uses by altering the url variable.

Now let me make a note before I get anyone in trouble. Taking material from a site without permission can be seen as a copyright violation, So I don't advise taking any info from any site without permission. Especially Nasdaq. Unless you like tangling with the super-congolomo with extremely deep pockets type.

I have to give credit to Frank Leahy from Wired for his article on using IIS extensions in Java. Without his help I wouldn't have been able to write this article.

Happy Programming!


Attachments:

  • StringGrabber.java in text format
  • StringGrabber.asp in text format


    Related Links:

  • http://www.microsoft.com/java
  • http://www.gamelan.com
  • http://www.webmonkey.com/java


    Ian Stallings is a 26 year old Software Engineer from the Washington DC area. He has experience in Internet/Intranet development using ASP, VB, Java, SQL Server, and IIS. Prior to devoting his career to application development he worked as a systems administrator at a small ISP.

    When not developing applications or tinkering with computers, he masquerades as a normal human being


  • ASP.NET [1.x] [2.0] | ASPMessageboard.com | ASPFAQs.com | Advertise | Feedback | Author an Article