dcsimg
www.webdeveloper.com
Results 1 to 5 of 5

Thread: display HTML-tags and images in one servlet

  1. #1
    Join Date
    Oct 2004
    Location
    Heidelberg, Germany
    Posts
    6

    display HTML-tags and images in one servlet

    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

  2. #2
    Join Date
    Oct 2004
    Location
    Heidelberg, Germany
    Posts
    6

    Talking got the answer!

    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.

  3. #3
    Join Date
    Nov 2003
    Location
    Jerryville, Tejas
    Posts
    11,715
    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.)

  4. #4
    Join Date
    Oct 2004
    Location
    Heidelberg, Germany
    Posts
    6
    Thanks for the tip!
    Its nice to know that somebody cares about things like that!

  5. #5
    Join Date
    Nov 2003
    Location
    Jerryville, Tejas
    Posts
    11,715
    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.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles