I've had a search through the archives but could not find any discussion on
this specific problem with relative URL's in JSPs.  I must be doing
something stupid, because this should happen to everyone?

I forward from a servlet to JSP and the JSP contains static relative links
to other pages.  In this case it's the reference to a CSS style sheet in the
same directory as the JSP, eg.

   <link rel="stylesheet" type="text/css" href="style.css">

However, because the browser originally submitted a request to the Servlet's
URL (eg. http://host/app/servlet/action) it interpretes these links relative
to that url and goes looking for the style sheet at
http://host/app/servlet/style.css.  Not completely unexpected I guess...

I have tried using the HTTPServletResponse.encodeURL and encodeRedirectURL
methods in the JSP to no avail, eg.

   <link rel="stylesheet" type="text/css"
href="<%=response.encodeURL("style.css")%>">

I guess these only add the stuff for session tracking, they don't seem to
allow for the modified HttpServetRequest URI in force in after forwarding to
the JSP code ?

It looks like I could set the JSP page's base location with something like

<head>
  <base href="<%=request.getRequestURI()%>">
</head>

Then, other relative links on the page might should work?  For some other
strange reason the CSS link still doesn't work with this, I think it might
be a mime type thing in tomcat, because if I go directly to JSP it works???

But even this seems like a lot of trouble to do on every page and I haven't
seen it discussed before.  How are other people handling this?  Or am I
missing something simple and its just too late at night for me to be working
on this stuff ?:-)

Thanks

Drew Cox

===========================================================================
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

Reply via email to