Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Multiple images from a servlet

 
Amit Malhotra
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm fairly new to web application development...so 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?

Thanks.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64633
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
D Rog
Ranch Hand
Posts: 472
Linux Objective C Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13056
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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

Bill
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic