beautypg.com

Polycom IP Phone 1725-17693-210 Rev. A User Manual

Page 25

background image

Application Development

2 - 15

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<%@page

import="java.io.File,java.io.IOException,java.net.URL,java.awt.image.B

ufferedImage,javax.imageio.ImageIO"%>

Stock Quote

<%

// 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;}

}

%>

4.

Configure the Web server to deploy the above JSP file.
For example, if you are using Apache Tomcat to try this example, put this

file into the webapps\PLCM folder of Tomcat.