aspose file tools*
The moose likes Servlets and the fly likes using servlet to create a html page with embedded Image Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "using servlet to create a html page with embedded Image" Watch "using servlet to create a html page with embedded Image" New topic
Author

using servlet to create a html page with embedded Image

ruilin yang
Ranch Hand

Joined: Feb 25, 2001
Posts: 334
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
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4456
    
    6

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).]


Junilu - [How to Ask Questions] [How to Answer Questions]
ruilin yang
Ranch Hand

Joined: Feb 25, 2001
Posts: 334
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
SoonAnn Lim
Ranch Hand

Joined: Jun 21, 2001
Posts: 155
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.
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

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.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12769
    
    5
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

Joined: Feb 25, 2001
Posts: 334
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
Rancher

Joined: Mar 22, 2000
Posts: 12769
    
    5
"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

Joined: Feb 25, 2001
Posts: 334
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
Jason Menard
Sheriff

Joined: Nov 09, 2000
Posts: 6450
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

Joined: Feb 25, 2001
Posts: 334
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

Joined: Jun 21, 2001
Posts: 155
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: using servlet to create a html page with embedded Image