jQuery in Action, 2nd edition*
The moose likes Tomcat and the fly likes Image problem with JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Image problem with JSP" Watch "Image problem with JSP" New topic
Author

Image problem with JSP

Abiodun Okusolubo
Ranch Hand

Joined: Apr 25, 2004
Posts: 72
Check out this simple jsp code,

<img src="tomcat.gif"> <br>
<img src="header.gif"> <br>
<img src="jakarta-logo.gif"> <br>

The irony is I created the header.gif using paint, the other two gifs were copied from tomcat examples. The problem here is I can't load any image I create except those copied from tomcat examples. I also created images using adobe photoshop, still no way around it.

However, when run the same code in html, exactly the same situation.

Is there anything I am doing wrongly or is there anything about how tomcat reads images that is not specify in the Headfirst servletandjsp text book I am using.
However, the servlet version I'm using is version 5.0.

Any advice will be welcome

Thank you.


SCJP, SCWCD, SCJD : in the making.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60785
    
  65

Moved to the HTML/Javascript forum.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60785
    
  65

Images are images; they'll either display or they won't. And whether the img tag is in a plain html page or one dynamically generated, via JSP or otherwise, is moot.

Firstly, are the URLs correct? You are using a relative URL which can be iffy.

Secondly, do the images display in the browser when open them directly (File > Open..)?
If not, something is wrong with your image files. If so, then the URLs are the most likely culprit.
Abiodun Okusolubo
Ranch Hand

Joined: Apr 25, 2004
Posts: 72
First I must thank you very much for your reply.
All the images and, html and jsp are in the same folder. Without using the Tomcat container, all the images worked as the should.
But as soon as I run tomcat and then comes the problem. I also noticed when i changed the Image type for the okay images to jpg, they also failed to show up.
This problem shows up when I am using tomcat to test the site I am building.

thank you.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60785
    
  65

Check the HTML sent to the page to see if it formatted as you think it should be.

Since your problem seems to be Tomcat-specific, I'm shifting this topic to the Tomcat forum.

You didn't set any funky mime-type mappings in the Tomcat config, did you?
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

As far as I know, MS-Paint can only create bitmaps ".bmp".
It is possible that you gave a ".gif" extension to a bitmap file?

I'm thinking that the browser is figuring out the file type when you hit it directly from the file system but getting confused when fetched via Tomcat because Tomcat is seeing the "gif" extension and sending incorrect mime-type instructions.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41125
    
  45
Paint can create GIFs as well as BMPs (and JPEG, TIFF, PNG), but the default is indeed BMP. As suggested, make sure that your image is really a proper GIF, and not some other format with a ".gif" extension.


Ping & DNS - my free Android networking tools app
 
wood burning stoves
 
subject: Image problem with JSP
 
Similar Threads
Problem in displaying Images
Image problem with JSP
Context root problem
Image problem with JSP
Unable To load image in JSP file