You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Ray Tayek <rt...@attbi.com> on 2003/03/04 03:19:33 UTC

Re: forward request to static html page loses path for included images?

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?).

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.

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: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: forward request to static html page loses path for included images?

Posted by Ray Tayek <rt...@attbi.com>.
At 11:57 PM 3/3/03 -0800, you wrote:

>"Ray Tayek" <rt...@attbi.com> wrote in message
>news:5.2.0.9.2.20030303180918.02dd7410@mail.attbi.com...
> > 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. ...
> > >
> > >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 ...
> > >
> > >Are you using "getNamedDispatcher"? ...
> >
> > i was using getRequestDispatcher(). but i have changed that to use
>redirect
> > (which works, but may cause me some problems later with session   - ...
>
>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 could do that and may if i need to go back to using forward.


> >
> > i found some sort of answer in jason hunters book (2nd edition) on page
> > 375. something about tomcat and relative links being broken ...
>
>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.  ...

got it!

thanks for the info.

---
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: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: forward request to static html page loses path for included images?

Posted by Erik Price <ep...@ptc.com>.

Ray Tayek wrote:

> 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?).

There is a method of HttpServletResponse called "encodeRedirectURL" for 
this, so that when you redirect to another page, the session is maintained:

(in the "doGet" method of a Servlet:)

   // redirect to "somepage.jsp" but
   // preserve the session in the URL:
   String targetPage = "somepage.jsp";
   response.sendRedirect(
                response.encodeRedirectURL(targetPage));

But your suspicions are correct: if you redirect to a static page 
(non-JSP) at any point in your application and the user has cookies 
disabled, there is no way to encode the URLs on the static page to keep 
the user "in" the session.

Instead of redirecting to a static HTML page, make it a JSP and encode 
the URLs on it.


Erik


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: forward request to static html page loses path for included images?

Posted by Bill Barker <wb...@wilshire.com>.
"Ray Tayek" <rt...@attbi.com> wrote in message
news:5.2.0.9.2.20030303180918.02dd7410@mail.attbi.com...
> 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: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org