html and jpeg content in same page

User 406e62b321

11-06-2007 01:55:13

Hi Everybody,





I'm having trouble trying to stream an image to the client from a jsp. I can get the code from the examples provided by chemaxion to work (very nice, thank you very much for the examples!) but I cannot get text and the image to display.





Ideally what I would like to do is write some text to the client, write an image to the client, write some more text to the client, write another image to the client, etc.





I've also searched google and the google java groups for jpeg and jsp and didn't find anything that pointed me in the right direction.





Any help would be greatly appreciated.





The attached code is an attempt to output:





Test Page for Marvin jpeg Generator


IMAGE


good bye world





But all I get is the image.





Thanks in advance,


Julie

ChemAxon 7c2d26e5cf

11-06-2007 12:59:05

The problem is that you have mixed image and html source in the output.


If the response object type is "image/jpeg", you can not use HTML tags in the JSP source (only the image stream). If there are embedded html tags in the JSP source, the response will be an HTML.


Please see the third image export example, it demonstrates how you can embbed an image source into the html output.

User 406e62b321

11-06-2007 14:37:12

Thanks for the info!





Currently I am getting the structure string from a database. Ideally I would like to generate the image from the structure and send it directly to the client without creating a file on the server. It seems that there would be a performance hit if the file is written to the server disk and then read from disk from the server by the client. Also, by creating the file on the server I need to worry about cleaning the files off of the server when then are no longer needed.





Is it possible to send html and image content to the client without writing the file to the server?





If I do write the file to the server first when is it safe to clear it off?





If I do something like this will it work consistantly?





<html>


<body>


<image src="myFile" />


<% CleanUp.delete("myFile"); %>


...





Will loading all of the files in the <head> of the document and then calling the delete method in the <body> work?





Thanks again,


Julie

ChemAxon 7c2d26e5cf

11-06-2007 14:50:46

You can post the generated image directly to the client (without saving it on the server).


Please see the following example:


show_image5.jsp: source | online version