First of all, of course, writing JAVA code. Let's take a look at the source file of. java, which is not very difficult:
Return to the command line to compile the StringGrabber. java file, as you did just now. After the compilation is complete, put the compiled result file StringGrabber. class in the C:/WinNT/Java/TrustLib directory. In this way, you can access it in the ASP file.
The next step is to use VBScript to create an ASP file as follows:
<Html>
<Head>
</Head>
<Body>
<H2> StockGrabber Test
<%
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> ")
If Request. Form ("ticker") <> "then
StrTicker = Request. Form ("ticker ")
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>
It can directly connect to the Nasdaq website, extract the latest stock quotes and display them. Analyze the webpage content, find the first <B >$, find the ending sign </B>, and capture all the content. Of course, this function can be changed as needed to capture any desired string. For example, the title of a news website or weather report. You can also change the url variable to change the website to be extracted.
Of course, this is just a test. It is illegal to use others' information without permission. In particular, websites like Nasdaq are in trouble. Don't contact me. However, we can also see that using JAVA in ASP is easier and more efficient. It seems easier to create a JAVA class than to create an ActiveX component in VB or VC. Of course, this depends on the situation, but JAVA is a good choice for some applications on the Internet.