tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Schultz <>
Subject Re: Links to relative URL's from a JSP
Date Mon, 24 Jul 2006 20:07:24 GMT

> Whenever I access "catalogue.jsp" by entering in its absolute URL,
> everything works fine.  I can still have my relative img links to the
> images contained in the same folder, e.g., <img src="image.jpg">
> However, if "catalogue.jsp" is accessed by the servlet forwarding the
> request and response objects to "catalogue.jsp" then none of the usual
> relative URL's work.  In fact, the servlet will not even compile correctly:

I think these are unrelated issues; you are getting a
ClassNotFoundException, not a JSP compilation error. Why is something
looking for a class called catalogue.css?

The standard practice for including "relative" URLs is, in fact, /not/
to use them. Instead, use absolute URLs -- but since the "context path"
can change given the deployment configuration, you can use the following
(relatively standard) trick:

<img src="<%= request.getContextPath() %>/your/full/path/image.png" />
instead of
<img src="../relative/path/image.png" />

Note that if your webapp's context name is "myApp", then the URL will
look like this:


but you should omit the "/myApp" in the path that you include in your
JSP. Otherwise, the URL generated will be "/myApp/myApp/your/full/...".


View raw message