Click to See Complete Forum and Search --> : display HTML-tags and images in one servlet


JohannaMos
10-15-2004, 04:24 AM
Hello everybody!

I have a problem concerning servlets:

I want to display a chart (*.jpeg) and HTML-tags (a table filled with values) one a servlet.

The problem is (at least I think this is the problem): you can't use response.setContentType("text/html") and response.setContentType("image/jpeg") together. Is this right?

So how would I get the image into the page?

I thought of something like creating one servlet with content type "image" and one servlet with content type "text" which calls the chart-servlet.

Would this work?
And what would the html-tag to call the image be? Is it the <img> tag?

Thanks in advance, Johanna

JohannaMos
10-15-2004, 05:20 AM
I solved my problem:

I made one servlet with response.setContentType("image/jpeg") to create the image. With another servlet with response.setContentType("text/html") I displayed the table and used a <img> tag with the URL of the "image" servlet to display the image.

ray326
10-15-2004, 10:59 PM
That's the correct answer except for one thing. The servlet responsible for displaying the page should be replaced with a JSP. (Not incorrect but not a best practice.)

JohannaMos
10-18-2004, 02:29 AM
Thanks for the tip!
Its nice to know that somebody cares about things like that!

ray326
10-18-2004, 12:58 PM
Originally posted by JohannaMos
Thanks for the tip!
Its nice to know that somebody cares about things like that! You're welcome. I guess I care about such things because that's why they pay me the big bucks (yeah, right). Anyway I've found over the years that "best practices" mean easier development, enhancement and maintenance and I'm all about easy. :D