File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes Unable To load image in JSP file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Unable To load image in JSP file " Watch "Unable To load image in JSP file " New topic
Author

Unable To load image in JSP file

Subbarao Kondabala
Greenhorn

Joined: May 17, 2005
Posts: 27
Hi,

I had written code in my JSP file as follows

<img src="/images/fish.gif">

The above code worked in websphere, but when I keep the same JSP file in tomcat5.0, I am unable to see the image.

For dispalying image in tomcat I need to do the following change.

<img src="images/fish.gif">

If I remove / before images then the code got worked.

I need the same code should work in tomcat also without doing modifications.

Can any one please help regarding this.

Thanks in advance

Subbarao
[ April 16, 2007: Message edited by: Bear Bibeault ]

Thanks and Regards,
Subbarao Kondabala
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Preceding a relative URL with a slash in a Java web app will only work if your app is the ROOT app on the server. If it is anything else you are skipping the contextPath.

The best way to build links is to make them relative to the root of the application by reading the contextPath from the request object:

Example:


Or, for pre JSP2.0 containers
[ April 16, 2007: Message edited by: Ben Souther ]

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Subbarao Kondabala
Greenhorn

Joined: May 17, 2005
Posts: 27
Thanks Ben.

I heard like if we change sever.xml by writing <contex> tag we can directly use code of websphere in Tomcat.

If you know can you please let me know with example

Thanks and Regards,
Subbarao Kondabala
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Unable To load image in JSP file