Hi Damian,

I must say, until now I was a little dismayed at the lack of response to my
query.  I thought I must have not explained the problem sufficiently, or I
was missing something so simple I was being ignored.  Thanks for at
confirming this is a problem for others out there.

In the meantime, I have come up with a workaround/solution that will work on
this project.  It's simple really, just pretend the URL of the sent to the
controlling servlet IS the URL of your JSP.  For example, I invoke our login
screen with :

http://server/time/controller/displayLogin

It eventually forwards to a JSP to display the login screen, which if
accessed directly would be at the URL:

http://server/time/jsp/displayLogin.jsp

But, in the JSP code, I just pretend it actually lives in the /controller
directory of the web app and code all my static links relative to this
location.  For example, thes link to the CSS is now "../jsp/style.css".

This could be a problem if you also invoke your JSP's directly, or from
other servlets mapped to different directories.  But with the single
controlling servlet model it looks like it will be adequate.  Given the
nature of what I'm doing, maybe this is the only answer?

I am still very interested to hear how others have dealt with this issue.

Regards

Drew Cox

ps
Glad to hear you're enjoying the ride.  We must be at similar stages of
development.  Oh, just realised you're an Aussie too.  So there are some
other JSP sites around OZ....

> -----Original Message-----
> From: Damian Fauth [SMTP:[EMAIL PROTECTED]]
> Sent: Tuesday, January 18, 2000 11:41 AM
> To:   [EMAIL PROTECTED]
> Subject:      Re: How to encode relative URIs in JSP after forward from
> servlet (not for sessions)
>
> 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

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