• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

using servlet to create a html page with embedded Image

 
Ranch Hand
Posts: 334
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Anybody can help me on how to create a html page with embedded image inside the html page. In the html page I can put some navigation buttons also diplay some parameters about the image.
Thanks.
Ruilin
 
Sheriff
Posts: 17713
302
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just code something like this:


at UBB
[This message has been edited by JUNILU LACAR (edited June 27, 2001).]

[This message has been edited by JUNILU LACAR (edited June 27, 2001).]
 
ruilin yang
Ranch Hand
Posts: 334
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JUNILU,
Thanks a lots.
Would you please give me more comments. My situation is using a servlet to generate .gif on fly. I do not have a .gif file stored somewhere. My servlet needs to get data from a calling page, then use these data to construct a "off-screen" image, then send to client.
How to conduct this? Please give me more clarification.

Thanks,
Ruilin
 
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have not done this before, but i have some idea using C. I guess the idea work in Java too. I think you have to create the image pixel by pixel in 2D unsigned char arrays, then convert this image to .gif or jpg format and send it out using BinaryOutputStream(don't remember the exact class name) object. I am not sure java provide any ready class to produce .gif or .jpg image format. Check the documentation for this issue.
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The standard java class libraries has some unsupported Sun libraries. Included in this is the package com.sun.image.codec.jpeg that includes classes for creating, well, jpeg images.
I'm not aware of open source for creating gif, it might have something to do with the patent on the gif encoding algorithm.
Help much?
Dave.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Most books on servlets, including mine and Hunter & Crawford, have a section on creating images on the fly.
Your img= tag will point to a servlet with a parameter or two to indicate which image is required. You need the Java 2D image package which includes GIF and JPG encoders. I think that is still at:
http://java.sun.com/products/java-media
Bill

------------------
author of:
 
ruilin yang
Ranch Hand
Posts: 334
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
SoonAnn, David, and William,
I have generated .gif and sent to client and displayed inder the browser. It works fine for a bare graph and labbel, etc. This approach described in a few servlet books, as William said.
My problem is how to embed the graph (image) into a html so that I can display extra parameters about the graph (image) and also some navigation buttons.
Any comments on how to mix the servlet generated .gif with html.
Thanks in advance
Ruilin

 
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Any comments on how to mix the servlet generated .gif with html."
You have to "Think like a browser" when questions like this come up. A browser makes a separate request for every single resource that a HTML page refers to. A page does NOT mix data types.
You have to figure out a way for your servlet generated gif to be served by a separate request as generated by the img tag URL - lots of approaches are possible here.
Bill
 
ruilin yang
Ranch Hand
Posts: 334
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
William,
Thanks,
Could you give me more guidance on a approach on how to imlement this ?
I stucked with passing x[], y[] (can be many as 200 pairs) to the GraphServlet to generate "off-screen" image to send to client to display.
If I could pass all the required data x[],y[],etc. for ploting the graph in the following call
<img src = "http://machineNamwe ortNum/appNmae/servlet/GraphServlet">
I can just use a wrapper html (.jsp) page to disply an "html embedded image".
Please comments, that will help me a lots.
Thanks in advance.
Ruilin
 
Sheriff
Posts: 6450
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One thing you might be able to do:
In the servlet that generates the HTML page which houses the <img src="http:/servlet/GraphicServlet"> tag, before outputting this line, place an object which contains your x[] and y[] into the HttpSession. Your GraphicServlet may then retrieve the object from the HttpSession and have access to your values.
To do this you will want to create some simple class which contains the desired attributes.
Example:

Hope this helps.
Jason
 
ruilin yang
Ranch Hand
Posts: 334
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Jason,
I am trying this technique. If it works it would be a great solution for the problem.

Thanks again
Ruilin
 
SoonAnn Lim
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have another idea. You have use your servlet to create an image file and save it on the disk with appropriate name determined by the users' session or cookies. After that, output your html code using regular System.out.println statement to include this generated image using <img src="UserImageXXX.jpg"> where XXX can be the id obtained from session. This way, you may end up many image files on disk, but you can delete the images from the disk once the user leave the page. This way, you can put other parameters as you want to and other buttons.
 
This parrot is no more. It has ceased to be. Now it's a tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic