Craig,
On Sat, 4 Sep 1999 00:01:03 -0700, Craig R. McClanahan <[EMAIL PROTECTED]>
wrote:
>Leo Neumeyer wrote:
>
>> I read many postings from people having problems using
>> getServletContext().getRequestDispatcher(targetPage).forward(req, res);
>>
>> The problem seems to be that relative references in the target page will
>> not work because the base path is the original servlet path and not
>> the path of the target page. (Am I right?)
>>
>> Has anybody found a way to get forward() to work with static or JSP pages
>> that contain relative references?
>>
>> I'm using JRun with its builtin web server on Windows.
>>
>
>I can't speak for JRun in particular, having not used it, but you might want to
>read the API documentation for ServletContext.getRequestDispatcher() , quoted
>below in part:
>
> The pathname must be in the form "/dir/dir/file.ext".
>
I am using a relative path like "/dir/dir/file.ext". This works fine as
long as "file.ext" does not contain a relative reference. However if
"file.ext" contains, for example:
<img src="picture.gif">
then the web server tries to find it in:
http://localhost:port/servlet/picture.gif
instead of the doc root:
http://localhost:port/picture.gif
>
>If you specify a correct pathname, it is interpreted as relative to the context
>path for the servlet context in which you are operating. See the "Clarifications
>to the Servlet API 2.1 Specification" in the JSP 1.0 spec for more information on
>this.
>
I read this clarification and found the solution. This is roughly what the
spec says:
"...If the relative URL starts with with no '/', then the path is
calculated relative to the servlet dir, if it starts with '/' then the
URL is calculated relative to the DOCROOT..."
All I had to do to fix the problem is to add the '/' to the relative
ref, for example:
<img src="/picture.gif">
Thanks for the pointer Craig!
>Craig McClanahan
>
Leo Neumeyer
===========================================================================
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