Application Development
<!- - BODY END -
2.Configure the Web server to serve the above XHTML file.
For example, if you are using Apache Tomcat to try this example, put this file into the webapps\PLCM folder of Tomcat.
3.Write an application that is going to retrieve the stock information from a data service provider.
For this example, this application will be retrieving stock information from Yahoo and will send it to the Microbrowser. This application is written using a Java Server Page (JSP).
<?xml version="1.0"
<!DOCTYPE html PUBLIC
<html>
<head>
<title>Stock Quote</title> </head>
<body>
<%
// GETTING THE PATH WHERE BMP FILE HAS TO BE SAVED
String bmpFilePath = application.getRealPath(File.separator) + "quote.bmp";
//DEFINE URL FROM WHERE CONTENT TO BE RETRIEVED String stockUrl = "http://ichart.yahoo.com/t?s=";
//RETRIEVE THE STOCK SYMBOL FROM REQUEST
String stockSymbol = "PLCM"; // DEFAULT TO PLCM if ( request.getParameter("stockname") != null ) { stockSymbol = request.getParameter("stockname");
}
readAndConvertContentToBmp(stockUrl + stockSymbol, bmpFilePath, stockSymbol);
%>
<%!
//READ THE CONTENT FROM GIVEN URL AND THEN CONVERT THE CONTENT TO A BMP FILE
private void readAndConvertContentToBmp(String a_stockUrl, String a_filePath, String a_name) throws IOException {
try {
BufferedImage stockImage = ImageIO.read(new URL(a_stockUrl)); ImageIO.write(stockImage, "bmp", new File(a_filePath));
}
catch (IOException ex) { throw ex;}
}
%>
2 - 15