"Ray Tayek" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> At 01:04 PM 3/3/03 -0500, you wrote:
> >Ray Tayek wrote:
> >>hi, i am forwarding a request to a static html page that has some
> >>pictures included using <IMG SRC="images/help1.jpeg" ...> and using
> >>request.getRequestDispatcher("/help.html").forward(request,response);.
> >>the static html file file comes back sans images. but pointing a browser
> >>to http://tayek.com:8080/feb/help.html works fine. seems like the path
> >>that the static page inherits is hosed somehow. is there some way to set
> >>that path?
> >
> >According to SRV.8.4 of the Servlet 2.3 spec, "The Forward Method":
> >
> >"The path elements of the request object exposed to the target servlet
> >must reflect the path used to obtain the RequestDispatcher. The only
> >exception to this is if the RequestDispatcher was obtained via the
> >getNamedDispatcher method. In this case, the path elements of the request
> >object must reflect those of the original request."
> >
> >I'm not sure how to interpret this exactly -- but it seems to say that
the
> >request object inherited in the "target servlet" (which I can only assume
> >also applies to "target HTML pages" as well, since targets of the
> >"forward" method can be either servlets, JSPs, or HTML pages) should
match
> >the path used to obtain the RequestDispatcher.
> >
> >Are you using "getNamedDispatcher"?  If so then the request object will
> >have the original HTTP request's path elements.  If you are using
> >"getRequestDispatcher" and passing it a path, then this would suggest
that
> >you are experiencing a bug in Tomcat.
>
> i was using getRequestDispatcher(). but i have changed that to use
redirect
> (which works, but may cause me some problems later with session - not
sure,
> but i want to have the guy stay in that same sessiosn even if goes off and
> looks at a static page  - i am worried about people who don't allow
cookies
> and if i don't do some kind of url encoding on the static file  i may get
> hosed - maube i should just copy it througt the servlet?).

Another way to go is to use absolute paths to your image files (e.g. <img
src="/feb/images/help1.jpeg">) and continue to use rd.forward.  At the risk
of breaking some very old browsers, you could also use the <base
href="/feb/"> html tag and keep your relative image paths.

>
> i found some sort of answer in jason hunters book (2nd edition) on page
> 375. something about tomcat and relative links being broken and the client
> not getting any notice that the file was served from the document root
> directory.
>

The problem is that the browser issues a seperate request for the image
files as it is parsing the html.  Since the browser has no way of knowing
that the request is the result of a 'forward', it resolves the relative URL
(i.e. "images/help1.jpeg") against the URL that it made the request for.  So
if the forwarding servlet was acessed from
http://myserver/feb/servlet/MyServlet, then the browser will try and fetch
the image from http://myserver/feb/servlet/images/help1.jpeg, and get a 404
response in return.



> thanks
>
> ---
> ray tayek http://tayek.com/ actively seeking mentoring or telecommuting
work
> vice chair orange county java users group http://www.ocjug.org/
> hate spam? http://samspade.org/ssw/




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to