tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mike Curwen" <>
Subject RE: ServletRequest's path elements not updated by calls to getRequestDispatcher()
Date Wed, 21 Jan 2004 19:19:02 GMT
That's the request dispatcher. Images and CSS are all 'called' from the
client and have nothing to do with the dispatcher.
If you type in
then to the browser, the resource requested is 'target'
and your image and css links, if they're relative, are going to be
relative to
If, OTOH, you ask for
then to your browser, you appear to be requesting a resouce in the
/target directory, and so images/css will be requested from there.

The simplest answer is:

replace "img=foo.gif"
with "img=/foo.gif"

> -----Original Message-----
> From: Alan Weissman [] 
> Sent: Wednesday, January 21, 2004 1:11 PM
> To: Tomcat Users List
> Subject: ServletRequest's path elements not updated by calls 
> to getRequestDispatcher()
> Hi Everyone - 
> I have a requirement to allow for URLs on a site of the 
> format where 'target' is not a real 
> directory or servlet, but redirects to another page on the site.
> To handle this, I have developed a ServletFilter which takes 
> the 'target' off the URL and attempts to do a server side 
> forward to a servlet using the RequestDispatcher.  This is 
> working for  I can get the 
> RequestDispatcher from either the ServletRequest or the 
> ServletContext and redirect to any target servlet with forward().  
> The problem arises where I try to handle 
> (note the trailing slash).  In this case, the 
> RequestDispatcher forwards to the target correctly HOWEVER, 
> all subsequent HTTP GETs for images, css, etc, are being 
> attempted on the wrong directory, /target/.  This seems to be 
> because the ServletRequest doesn't seem to adjust its path 
> elements accordingly.  For instance, if /target/ is supposed 
> to redirect to target.jsp using forward("/target.jsp") the 
> requests look like:

Of course, /target was never a real directory to begin with :)  

Now, According to the API doc for RequestDispatcher:

"For a RequestDispatcher obtained via getRequestDispatcher(), the
ServletRequest object has its path elements and parameters adjusted to
match the path of the target resource. "

Does anyone have any experience with this issue?  Is this a bug?  Is
there a workaround?

Thanks so much,

To unsubscribe, e-mail:
For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message