File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Multiple images from a servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Multiple images from a servlet" Watch "Multiple images from a servlet" New topic

Multiple images from a servlet

Amit Malhotra

Joined: Dec 14, 2006
Posts: 2

I'm fairly new to web application my question may appear standard to some of you, but I'll appreciate some pointers in the right direction.

I need to create a page which when somebody accesses using a GET request and passing in some parameters for stock tickers would show stock charts for those companies. My initial thought is that this would be done within a JSP page from which I would call a servlet and pass in each of those stock tickers one by one (thus making multiple servlet calls). Then those images returned would be displayed somehow in the JSP. Is that how it should work?

Also, initially I will just have some static images that my servlet will pull and display. But, in a real world scenariom where would these images be generated from? Let's say I want to show a chart for the last 5 years, that chart would obviously be different today than it will be 2 years from now. So somehow this chart needs to be generated dynamically. How would this be accomplished?

Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63858

Keeping in mind that a JSP is just a means to dynamically create an HTML page to be sent to the browser, how would you do this if you were writing a static HTML page?

[Asking smart questions] [About Bear] [Books by Bear]
D Rog
Ranch Hand

Joined: Feb 07, 2004
Posts: 472

Look for chart generation tools first. There are plenty of them, MSN live search will help you find one. Then you can create a servlet which will use this charting tool by supplying data and then return generated image to a browser. Calling of you servlet can look like:
<img src="http://mycoolcompany/mytickerapp/myticker.jsp?ticker=NVDA&period=2yers" border="0">

When your servlet gets such request, it should take parameters, based on them request data from database, then pass the data to charting tool, get image from charting tool as byte array and return this image back to a browser. Do not forget to set content type as image/gif or other format your charting tool supports.

Retire your iPod and start with HD Android music player Kamerton | Minimal J2EE container is here | Light weight full J2EE stack | and build tool | Co-author of "Windows programming in Turbo Pascal"
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13037

Tch! Image requests should be directed to a servlet. JSP have built in assumptions that they will be generating an html character stream.

I agree. Here's the link:
subject: Multiple images from a servlet
It's not a secret anymore!