Thanks, Scott.  That's pretty much just what I was looking for.  To make it even 
better, I'm having my servlet set the path info (/myfiles) as an attribute of the 
request.  That way I can dynamically build the base URL like so:

  <base href="http://<%= request.getServerName() %><%= request.getAttribute("Path") 
%>/">

Dave F.

-------- Original Message --------
Subject: Re: Forwarding & Relative Refs, cont'd
Date: Fri, 01 Oct 1999 12:35:44 -0700
From: Scott Ferguson <[EMAIL PROTECTED]>
Organization: Caucho Technology

How about adding a base section to the html head?  It's not perfect, but it might 
reduce the clutter:

<head>
<base href='http://hostname/myfiles'>
</head>

I don't know how well supported it is by the various browsers.

-- Scott

Dave Ferguson wrote:

> I'm looking for more clever solutions.
>
> My problem also occurs when I use RequestDispatcher.forward() to forward to a JSP 
>page (see original posting below).  In my case, the JSP page contains relative links 
>like <img src="images/picture.gif"> and they are not being found.  The JSP is not in 
>the server's root directory, but in a subdirectory called /myfiles (picture.gif is in 
>a directory called /myfiles/images).
>
> I know I can solve the problem by using <img src="/myfiles/images/picture.gif">, but 
>I don't want to hard-code any of this path information into the JSP.  I want to keep 
>the links relative to the JSP's location.
>
> Since my servlet that does the forwarding knows the path, I've thought about storing 
>a value in the session object (i.e., session.putValue( "Path", "/myfiles" ).  Then, I 
>could use <img src="<%= session.getValue("Path") %>/images/picture.gif">.  But my 
>concern here is that I don't want to muck up the HTML tags and potentially draw the 
>wrath of web page designers who may be frightened by such a thing.  Not to mention 
>they may be using GUI tools won't ever see the HTML.
>
> I can also make it work by using sendRedirect() instead of forward(), but of course, 
>I don't want the extra trip to the client.
>
> Is there a way to keep my relative links and still use forward()?
>
> Dave F.

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
FAQs on JSP can be found at:
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html

Reply via email to