This servlet lets you request stock quotes from Yahoo and return them as JSON array. How to use it: a) download stockPackage.jar and save it in WEB-INF/lib b) describe this servlet in web.xml file.
<servlet> <servlet-name>Stock</servlet-name> <servlet-class>com.jsos.stock.StockServlet</servlet-class> </servlet> c) describe a mapping for this servlet in web.xml file. E.g.:
<servlet-mapping> <servlet-name>Stock</servlet-name> <url-pattern>/servlet/stock</url-pattern> </servlet-mapping> Servlet accepts two parameters: q - commas separated list of tickets
The following example illustrates the usage. This code requests info about ORACLE stock.
JavaScript function f describes our callback.
<script language="JavaScript"> function f(info) { var s="Symbol:" + info[0].symbol+"\n" +"Name:" + info[0].name+"\n" +"Price:" + info[0].price; alert(s); } var e = document.createElement("script"); e.src = 'http://your_server/servlet/stock?q=ORCL&callback=f'; e.type="text/javascript"; document.getElementsByTagName("head")[0].appendChild(e); </script> For downloading: Stock package: stockPackage.jar
See also JSOS - the largest collection of servlets and filters.
|
Also in JSOS:
|