Interaction between Java and ASP (2)

Source: Internet
Author: User

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.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.