I have been wondering about this one too.
We have just started looking at Model II (MVC) JSP architecture as a
solution to the increasing complexity of our JSP templates and I like
the content/logic/model separation it provides - potentially it will
make it easier for our HTML guys - but the relative URL issue is likely
to confuse them and be a source of endless errors. Like Drew, I have
tried the <base href=""> tag (although I used
<base href="<%= request.getScheme() %>://<%= request.getServerName()
%>/jakarta/local/docs/">) but its not something I want to impose on our
HTML guys.
Is there some other solution such as forcing all access to a particular
web application (ie. some sort of servlet-mapping directive) to pass
through a particular servlet by default, avoiding the need to reference
your controlling servlet at all?
Damian
PS. By the way, I found the "Providing application resources to action
classes in single-servlet delegation model" thread particularly
illuminating and intend to try some of the approaches discussed.
Drew Cox wrote:
>
> 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
--
Damian Fauth Fairfax Interactive Network (F2)
Senior Software Engineer 201 Sussex Street
Ph: +61 2 9282 3528 Sydney NSW 2000
[EMAIL PROTECTED] http://www.f2.com.au
===========================================================================
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