Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Unable To load image in JSP file

 
Subbarao Kondabala
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Subbarao Kondabala
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic