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.
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:
|
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 formatStringGrabber.asp in text format
Related Links:
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




