tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ken Ramirez" <>
Subject Trouble with IMG tag, servlets, and JSPs
Date Wed, 27 Feb 2002 05:12:49 GMT
Hope someone can help:

I'm having a problem loading images from a JSP page when the page is
called from a servlet.  I'm performing a
forward from the servlet to the JSP, which then loads the images from a
subdirectory in the app's directory as follows:



The images are loaded from the JSP using the img tag as follows:

<img src="images/myimage.jpg" >

I've also tried src="/images/myimage.jpg" and this doesn't work.
However, if I call the jpg directly, everything shows up fine.
Of course in the real world, I need to get the forward to work so that I
can pass data from the servlet to the JSP.  I found
some information in the mailing list's archive regarding this problem
and someone suggested the following:

<IMG SRC="<%=request.getContextPath()%>/images/myimage.jpg">

This does work, but it just seems odd that you would have to do this,
especially given the fact that there is a context entry for
the app in the server.xml.  Isn't the purpose of the Context entry to:

	1.  Create and associate a Context object with the App and
	2.  Establish the base path for the app.
Seems kind of redundent that you would have to again retrieve the
ContextPath yourself, when it seems that Tomcat should do 
this for us or the Browser should receive the problem path so that it
knows where to get the images and CSS files from.  Instead,
what is actually sent back to the browser is the following path for the


Now what's interesting is that I looked in one of Tomcat's log files and
found the following exception for the images:

"StandardWrapper[/MasterMind:org.apache.catalina.INVOKER.theme]: Marking
servlet org.apache.catalina.INVOKER.theme as unavailable
2002-02-26 20:53:17 invoker: Cannot allocate servlet instance for path
javax.servlet.ServletException: Wrapper cannot find servlet class theme
or a class it depends on ..."

And in one of the other log files, I found the following error: - - [26/Feb/2002:20:53:17 -0500] "GET
/MyApp/servlet/images/myimage.jpg HTTP/1.1" 404 696

I'd like to get this to work without the hack I mentioned above.  Does
anyone have any suggestions?



Ken Ramirez - Principal/CTO
Master-Mind Consulting Services <> 
Ph - 570-688-9600
Fx - 208-275-2301

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message