On Mon, 18 Nov 2002, neal wrote:
> Date: Mon, 18 Nov 2002 16:12:29 -0800 > From: neal <[EMAIL PROTECTED]> > Reply-To: Tomcat Users List <[EMAIL PROTECTED]> > To: Tomcat Users List <[EMAIL PROTECTED]> > Subject: RE: auto-redirect to default page - undesired > > Well, cool idea but there's still a problem: > > I mean...The requestDispatcher *does* redirect to the right page *BUT* all > my relative links are broken. So, I tried mapping the forward servlet to > the path "/test" instead of just "/" and sure enough *that* url worked ... > relative paths just fine. So even though mapping to "/" did get the page to > call correctly, nothing in that page resolved correctly. Somehow its > context was off I guess. Do you know of some alternative syntax to "/" that > could be specified to indicate the root of the domain? I tried everything I > could think of and nothing else worked (e.g. "", "/*", "*", "*/", etc). > That's not a bug ... that's a feature :-). The reason relative references are often broken by RequestDispatcher.forward() comes from the fact that the reference is resolved by your *browser* (not by the server), against the request URI to which the request was originally submitted. The browser has no idea that the forward happened, so if it points into a different subdirectory of your webapp, it will typically fail. One workaround for this is to include an HTML <base> element nested in your <head> element. This will allow you to specify the absolute URL against which relative URLs are resolved -- you would typically set it to the absolute URL of the page file itself. That way, relative links will work when the page is accessed directly and when it is accessed via a forward. Implementing this idea is pretty tedious if you don't have a tag library that takes care of it for you, like the <html:base/> tag in Struts. > Thanks. > Neal Craig -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
